访问被拒绝::缺少授权的访问令牌。请求:MailboxService.GetThread。在GmailThread中使用getMessages()时

时间:2019-06-12 15:20:13

标签: google-apps-script gmail gmail-addons

我正在尝试在已发送邮件的线程中获取所有消息。在下面的代码中,我可以将所有已发送的线程以 [GmailThread GmailThread ..] 的形式发送到变量“邮件”中。此外,mails [0] .getId()给出了mails [0]的threadId。

var mails = GmailApp.search('in:sent');
Logger.log(mails[0].getMessages());

但是mails [0] .getMessages()返回运行时错误为

Access denied: : Missing access token for authorization. Request: MailboxService.GetThread.

这是我包含的范围。

"oauthScopes": [
"https://www.googleapis.com/auth/gmail.addons.execute",
"https://www.googleapis.com/auth/script.external_request",
"https://www.googleapis.com/auth/gmail.addons.current.message.action",
"https://www.googleapis.com/auth/gmail.addons.current.action.compose",
"https://www.googleapis.com/auth/gmail.compose",
"https://www.googleapis.com/auth/gmail.addons.current.message.metadata",
"https://www.googleapis.com/auth/gmail.readonly",
"https://www.googleapis.com/auth/gmail.modify",
"https://mail.google.com/"
]

现在我想要的是获取邮件中的所有邮件[0]。

2 个答案:

答案 0 :(得分:1)

here的api文档中,您可能缺少以下内容:

ngOnInit() {
// Init DataSource
this.dataSourceProjectSteps = new ProjectStepsDataSource(this.projectStepsStore);
const entitiesProjectStepsSubscription = this.dataSourceProjectSteps.entitySubject.pipe(
   skip(1),
   distinctUntilChanged()
).subscribe();
this.subscriptions.push(entitiesProjectStepsSubscription);
this.subscriptions.push(entitiesProjectStepsSubscription);
this.selectedPId = parseInt(localStorage.getItem('selectedpId'), 10);
if (!isNaN(this.selectedPId)) {              this.formGroup.get('projectsCombo').setValue(this.selectedProjectId.toString());
  this.loadFeesPerStepByProject(this.selectedProjectId);
}

}

/**
* On Destroy
*/
ngOnDestroy() {
   this.subscriptions.forEach(el => el.unsubscribe());
}

loadFeesPerStepByProject(id: number) {
   this.projectStepsStore.dispatch(new ProjectDataByPhasePageRequested({projectId: id}));
    }

答案 1 :(得分:0)

我在使用Apps Script GMail库时遇到了类似的错误。我改用GMail API服务。尝试使用它们https://developers.google.com/gmail/api/v1/reference/我对此没有遇到任何问题。

相关问题