我在Gmail API中逐步提出了一个简单的请求。
根据我打电话的所有说明:
var request = gapi.client.gmail.users.messages.send({
'userId': 'me',
"payload": {
"headers": [
{
"name": "To",
"value": "########@gmail.com"
}
]},
'raw': 'SEVMTE8gTVkgREVBUiBGUklFTkQ='
});
request.then(()=>{console.log('yep')})
但收到错误:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalidArgument",
"message": "Recipient address required"
}
],
"code": 400,
"message": "Recipient address required"
}
}
答案 0 :(得分:1)
Users.messages: send中列出了使用Gmail API发送到电子邮件的正确格式:
function sendMessage(userId, email, callback) {
// Using the js-base64 library for encoding:
// https://www.npmjs.com/package/js-base64
var base64EncodedEmail = Base64.encodeURI(email);
var request = gapi.client.gmail.users.messages.send({
'userId': userId,
'resource': {
'raw': base64EncodedEmail
}
});
request.execute(callback);
}
有关如何使用此方法的更生动的示例,请查看此SO post:
[...]需要在
raw
参数中传递完整的消息,请参阅示例:From: John Doe <jdoe@machine.example> To: Mary Smith <mary@example.net> Subject: Saying Hello Date: Fri, 21 Nov 1997 09:55:06 -0600 Message-ID: <1234@local.machine.example> This is a message just to say hello. So, "Hello".
因此,在base64对完整消息进行编码后,将其传递给
raw
参数而不使用任何其他参数,它可以正常工作。