我正在尝试通过JS Gmail API发送邮件来获取hello world。根据this,我已正确授权(可以列出标签)。
我使用以下代码,在浏览器中运行:
const message =
"From: my.email@gmail.com\r\n" +
"To: my.email@gmail.com\r\n" +
"Subject: As basic as it gets\r\n\r\n" +
"This is the plain text body of the message. Note the blank line between the header information and the body of the message.";
// The body needs to be base64url encoded.
const encodedMessage = btoa(message)
const reallyEncodedMessage = encodedMessage.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '')
gapi.client.gmail.users.messages.send({
userId: 'me',
requestBody: {
// same response with any of these
raw: reallyEncodedMessage
// raw: encodedMessage
// raw: message
}
}).then(function () { console.log("done!")});
这将给出一个HTTP 400响应:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalidArgument",
"message": "'raw' RFC822 payload message string or uploading message via /upload/* URL required"
}
],
"code": 400,
"message": "'raw' RFC822 payload message string or uploading message via /upload/* URL required"
}
}
这是使用https://apis.google.com/js/api.js
上提供的JS。取自MSDN和elsewhere的RFC822示例。据我所知,对RFC822消息进行网页安全的base64编码是这个API的标准。在Firefox和Chrome中也有同样的错误。
我哪里错了?
https://stackoverflow.com/questions/51900190
复制相似问题