【发布时间】:2021-08-07 18:35:46
【问题描述】:
我已经有一个查询谷歌日历 api 的项目。 我想通过查询 google mail api 更进一步。 在我的项目中,我激活了邮件 API 我已经在我的 javascript 应用程序中添加了 discoveryDocs,就像这样
[
"https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest",
"https://www.googleapis.com/discovery/v1/apis/gmail/v1/rest"
]
还有这样的作用域
"https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/calendar.events https://mail.google.com/"
我的客户端的初始化是这样完成的:
initClient(): void {
gapi.client.init({
apiKey: 'ma_api_key',
clientId: 'my_client_id.apps.googleusercontent.com',
discoveryDocs: [
"https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest",
"https://www.googleapis.com/discovery/v1/apis/gmail/v1/rest"
],
scope: 'https://www.googleapis.com/auth/calendar https://www.googleapis.com/auth/calendar.events https://mail.google.com/',
}).then(() => {
console.log('ok')
});
}
我仍然可以获取我的日历和事件,但我无法使用此代码获取我的标签:
getMails(): void {
console.log(gapi);
gapi.client.gmail.users.labels.list({
'userId': 'me'
}).then(function(response) {
var labels = response.result.labels;
console.log(labels);
});
}
请问我错过了什么?
谢谢
【问题讨论】:
标签: javascript gmail-api google-api-js-client