400 错误。需要收件人地址。 JavaScript
400 error. Recipient address required. JavaScript
我在 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"
}
}
在 Gmail API 中发送电子邮件的正确格式在 Users.messages: send:
中说明
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:
[...] the complete message needs to be passed in the raw
parameter, see the example:
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".
So after base64 encoding the complete message, passing it in the raw
parameter without using any other parameter, it works fine.
我在 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"
}
}
在 Gmail API 中发送电子邮件的正确格式在 Users.messages: send:
中说明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:
[...] the complete message needs to be passed in the
raw
parameter, see the example: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".
So after base64 encoding the complete message, passing it in the
raw
parameter without using any other parameter, it works fine.