【发布时间】:2017-01-27 23:02:54
【问题描述】:
我正在创建一个应用程序,以便使用 Google Apps 脚本为应用程序用户的 gmail 帐户添加手表。
为了测试手表的工作情况,我使用了以下应用脚本代码,该代码是从 Spencer Easton (https://www.youtube.com/watch?v=wjHp9_NAEJo) 的 youtube 教程中获得的
function doPost(e)
{
var message = JSON.parse(e.postData.getDataAsString()).message;
var data = Utilities.newBlob(Utilities.base64Decode(message.data)).getDataAsString();
var ss = SpreadsheetApp.openById('my_google_sheet_id').getSheets()[0];
ss.appendRow([new Date(), message.message_id, data, "newMail"]);
return 200;
}
function enrollEmail() {
var watchRes = Gmail.newWatchRequest();
watchRes.labelIds = ["INBOX"];
watchRes.labelFilterAction = "include";
watchRes.topicName = "projects/project-id-12345/topics/gmailTrigger";
var response = Gmail.Users.watch(watchRes, "me");
}
function doGet()
{
enrollEmail();
}
然后我使用以下步骤发布了应用程序:
1. Deploy as web app
2. Execute the app as: Me
3. Who has access to the app: Anyone, even anonymous
现在手表可以正常使用我的 gmail 帐户了。
但我的要求是监视在我的应用中通过身份验证的所有用户。
所以,我尝试使用以下步骤发布应用:
1. Deploy as web app
2. Execute the app as: User accessing the web app
3. Who has access to the app: Anyone
现在,该应用要求对访问 Web 应用 URL 的用户进行身份验证。但手表不适用于用户的 gmail 帐户和我的 gmail 帐户。
我再次使用第一种方法发布了应用程序(以:我身份执行应用程序),现在手表适用于经过身份验证的用户的帐户和我的帐户。
如何配置 Google Apps 脚本,以便我可以为验证我的应用的用户添加手表。
【问题讨论】:
-
"但手表不适用于用户的 gmail 帐户和我的 gmail 帐户。"你能扩展一下吗?究竟是什么不起作用?
-
将新电子邮件添加到收件箱时不会调用 doPost()。 (用户帐户和我的帐户)
标签: javascript google-apps-script gmail-api