我的Alexa已链接到我的Gmail帐户。所有凭证信息都会自动在Alexa中填写。我的Alexa技能每45分钟自动生成一个accessToken。如何使用GET从Gmail读取未读的电子邮件内容?根据另一篇文章,我需要做类似的事情
GET https://www.googleapis.com/gmail/v1/users/me/threads?labelIds=INBOX&labelIds=UNREAD&access_token=${accessToken}
那么我到底需要做什么来获取url?
我尝试了
const REQUEST = require('request');
var url = `https://www.googleapis.com/gmail/v1/users/me/threads?labelIds=INBOX&labelIds=UNREAD&access_token=${accessToken}`;
console.log(url);
REQUEST.get(url, (error, response,body )=>{
console.log('............')
var temp;
temp = JSON.parse(body);
console.log(temp);
console.log('error:', error); // Print the error if one occurred
//console.log('statusCode:', response && response.statusCode); // Print the response status code if a response was received
console.log('body:', body); // Print the body
});
,但是它不起作用。这是错误消息。
{ error:
{ errors: [ [Object] ],
code: 403,
message: 'Insufficient Permission' } }
答案 0 :(得分:0)
问题已解决。这是有效的代码。
const axios = require('axios');
var url = `https://www.googleapis.com/gmail/v1/users/me/threads?labelIds=INBOX&labelIds=UNREAD&access_token=${accessToken}`;
console.log('URL.......................'+url);
await axios.get(url)
.then(function (response) {
console.log('response.................'+temp);
})
.catch(function (error) {
console.log('error...........................'+error);
});