I have been trying to solve this problem all the day but I can't find where the error. I am making a program to detect when I receive an mail in my gmail and write that mail in a Google Spreadsheet, I am using the Gmail API and Google Apps Script. This is my code:
gs code is :
function doPost(e) {
var message = JSON.parse(e.postData.getDataAsString()).message
var data = Utilities.newBlob(Utilies.base64Decode(message.data)).getDataAsString()[0];
var ss = SpreadsheetApp.openById('1b8s5PLItCsmk8l1q0T1KHYOzjW7iDv4sRXSFvAxVFbQ').getSheets()[0];
ss.appendRow([new Date(), message.message_id,data]);
return 200;
}
function capturemail(){
var WatchRes = Gmail.newWatchRequest();
WatchRes.labelIds = ["INBOX"];
//WatchRes.labelFilterAction = "include";
WatchRes.topicName = "projects/proyecgmailyou/topics/mailsuc";
var response = Gmail.Users.watch(WatchRes,"[email protected]");
Logger.log(response);
}
The function doPost() I put in a web: https://script.google.com/a/uc.cl/macros/s/AKfycby8gOrWrMDkaAlgNdXNHl2J424Hvv0yu2CKKhJQW41Ka3Xa55g/exec
and then I try to run the function capturemail but appear the next error :
The API call to gmail.users.watch failed with the error: Invalid topicName does not match projects/sys-72285619869091378116913905/topics/*
and is so strange because i never use this name"sys-72285619869091378116913905" and i didn t see it in same other place
also i give the permission to [email protected]
I think that the problem was the id of the project so I review that part and this is what I find:
I also try to change the topicName for :
projects/sys-72285619869091378116913905/topics/mailsuc
but appear this other error:
The API call to gmail.users.watch failed with the error: Error sending test message to Cloud PubSub projects/sys-72285619869091378116913905/topics/mailsuc : Resource not found (resource=mailsuc).
however I am sure that I have that resource create because I did here:
and the last thing i used this video of youtube to guide me youtube.com/watch?v=wjHp9_NAEJo
There are new steps to change the Cloud Project for your Apps Script to a "standard" Cloud Platform project (if you're using the "new editor"):
The watch function documentation has this to say about the project:
Note that the "my-project-identifier" portion must exactly match your Google developer project id (the one executing this watch request).
sys-72285619869091378116913905
is presumably the project ID of the project that the Apps Script is running as. This is a "default Cloud Project" as described here. This obviously doesn't match proyecgmailyou
.
To fix this, you can change the Cloud Project for your Apps Script to a "standard" Cloud Platform project with the following steps:
Authorizations will be lost, but after that the Apps script will be running in your cloud project and so can use a topic from that project. Note: With the new App Script editor you should follow these steps ;
click on settings from left side menus
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With