WebApp publishes, get valid History ID, no changes to spreadsheet
Nathaniel-MacIver opened this issue · 4 comments
Hey Spencer, nice work on this GAS applet. It really helps new coders like me to quickly leverage complex tools to deliver new value to G-Suite customers!
I've created two versions of this project, one running this repository, and the other manually copying you're instruction video on Youtube. I can confirm that the projects register in the Chrome store, libraries and APIs are checked off, GMail service account is added as Pub/Sub Publisher, and Topic/Subscription is created. When running enrollEmail(), I can pull a valid History_Id that pulls data using the API explorer. I can even confirm that I can append a row to my log spreadsheet with test data while enrolling the user's email.
However, after letting the push service sit for two hours (and 12 emails later), the spreadsheet does not register a single change. Since this is a push service, I tried pushing a manual message to the thread, with no change. Is there any way I can debug through this without resorting to coding the pull method? I'd rather not flip to something that needs to be run manually.
Here is a copy of my most recent working code, sans privacy info:
code.gs
`
var EMAIL = Session.getActiveUser().toString();
function doPost(e) {
var ss = SpreadsheetApp.open(DriveApp.getFilesByName('Episode_Log').next()).getSheets()[0];
ss.appendRow(['Push was recieved'+ new Date()]);
try{
var message = JSON.parse(e.postData.getDataAsString()).message;
var data = Utilities.newBlob(Utilities.base64Decode(message.data)).getDataAsString();
ss.appendRow([new Date(), message.message_id, data]);
}
catch(e){ss.appendRow(['failure', e]); }
return 0;
}
function enrollEmail() {
var watchRes = Gmail.newWatchRequest();
watchRes.labelIds = ["INBOX"];
watchRes.labelFilterAction = 'include';
watchRes.topicName = 'projects/project-id-123456789/topics/eWarning';
var response = Gmail.Users.watch(watchRes, EMAIL);
Logger.log(response);
var ss = SpreadsheetApp.open(DriveApp.getFilesByName('Episode_Log').next()).getSheets()[0];
ss.appendRow(['Manual Test']); //This works
}
function checkHistory(){
Logger.log(Gmail.Users.History.list(EMAIL, {startHistoryId: '****'})); //works with a valid ID
}
`
For reference, I posted this to Google's App script support channel at StackOverflow. I'll close the issue if I get a solution through that channel. Some posts seem to indicate push notifications may not be accepted for Google Appscript domains? The feature request portal still has an open request for it.
Well, In my rush to get a production script going, I forgot that I could just create a small script to check a mailbox for messages under a label and process new messages that way, which takes care of my need. I'll close this topic and leave the thread up on StackOverflow.
I use this technique in-house production with apps scripts. Ill take a look and see if something in this repo need updating.
I'm having this same issue. I can also find messages using history ID, but nothing ever hits the spreadsheet. Would love some direction! Thanks in advance!!