【发布时间】:2019-10-08 06:50:06
【问题描述】:
我整天都在尝试解决这个问题,但我找不到错误在哪里。我正在制作一个程序来检测我何时在我的 gmail 中收到邮件并将该邮件写入 Google 电子表格,我正在使用 Gmail API 和 Google Apps 脚本。这是我的代码:
gs 代码是:
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,"rjdelrio@uc.cl");
Logger.log(response);
}
函数doPost()我放一个web:https://script.google.com/a/uc.cl/macros/s/AKfycby8gOrWrMDkaAlgNdXNHl2J424Hvv0yu2CKKhJQW41Ka3Xa55g/exec
然后我尝试运行函数 capturemail 但出现下一个错误:
The API call to gmail.users.watch failed with the error: Invalid topicName does not match projects/sys-72285619869091378116913905/topics/*
而且很奇怪,因为我从不使用这个名字“sys-72285619869091378116913905”,而且我没有在同一个地方看到它
我也授予 gmail-api-push@system.gserviceaccount.com 权限
我认为问题出在项目的 id 上,因此我查看了该部分,这就是我发现的:
我也尝试将 topicName 更改为:
projects/sys-72285619869091378116913905/topics/mailsuc
但出现此错误:
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).
但是我确信我已经创建了该资源,因为我在这里做了:
最后我用这个 youtube 的视频来指导我 youtube.com/watch?v=wjHp9_NAEJo
【问题讨论】:
-
sys-72285619869091378116913905 来自哪里?您显示的屏幕截图的项目名称为 proyecgmailyou。
-
该名称在哪里可以找到?
-
我很少用这个名字,但是我用这个 youtube 视频来指导我 youtube.com/watch?v=wjHp9_NAEJo
标签: google-apps-script google-cloud-platform gmail-api watch google-cloud-pubsub