【发布时间】:2016-04-05 09:48:52
【问题描述】:
免责声明:
- 我已经关注了谷歌自己的Node.js quickstart guide,并成功连接并使用了
gmail.users.labels.list()功能。 - 我已经检查了这里的问题/答案,例如this one(没有使用我所询问的 Node.js API)或this one(类似于this one),这显然是我的同一个问题有,但解决方案不起作用。
我的问题:
使用Google's Node.js API 时,我在尝试发送电子邮件时遇到错误。错误是:
{
"code": 403,
"errors": [{
"domain": "global",
"reason": "insufficientPermissions",
"message": "Insufficient Permission"
}]
}
我的设置:
fs.readFile(secretlocation, function processClientSecrets(err, content) {
if (err) {
console.log('Error loading client secret file: ' + err);
return;
}
authorize(JSON.parse(content), sendMessage);
});
function sendMessage(auth) {
var raw = makeBody('myrealmail@gmail.com', 'myrealmail@gmail.com', 'subject', 'message test');
gmail.users.messages.send({
auth: auth,
userId: 'me',
message: {
raw: raw
}
}, function(err, response) {
res.send(err || response)
});
}
函数processClientSecrets来自我上面提到的谷歌指南。它读取我的.json 文件,其中包含我的access_token 和refresh_token。 makeBody function 是用于制作编码正文消息。
在配置变量中我也有:
var SCOPES = [
'https://mail.google.com/',
'https://www.googleapis.com/auth/gmail.modify',
'https://www.googleapis.com/auth/gmail.compose',
'https://www.googleapis.com/auth/gmail.send'
];
为什么它应该起作用:
- 授权过程适用于
gmail.users.labels.list()方法。 - 如果我在 Google's test page 进行测试,我正在测试的消息正文可以正常工作。
我的问题:
我的设置错了吗? API有变化吗?我错过了什么?
【问题讨论】:
-
@AboulEinein 我有,但还是不行,谢谢指点。在Google tool 中进行测试时,我也必须拥有它。目前我拥有这些 Auth 范围:
https://mail.google.com/, gmail.compose, gmail.modify, gmail.send -
@Sergio Darn :( 那我不知道。希望其他人可以加入。
-
@Tholle 发现了我的问题。感谢您检查这个!
-
@Sergio 太棒了!没问题。 :)
标签: node.js gmail-api google-api-nodejs-client