我正在尝试使用服务器端的node.js向Gmail发送消息API发送请求,但没有成功。我遇到了以下错误:
输入参数oauth2token和raw是有效的,事实上,如果我使用Google OAuth 2 playground(https://developers.google.com/oauthplayground)并将令牌和原始值作为值,电子邮件确实会发送。有人能看出我错过了什么吗?
body: '{
"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"
}
}'
}
输入参数oauth2token和raw是有效的,事实上,如果我使用Google OAuth 2 playground(https://developers.google.com/oauthplayground)并将令牌和原始值作为值,电子邮件确实会发送。有人能看出我错过了什么吗?
function sendMail(oauth2token, raw) {
context.log('Token: ' + oauth2token);
context.log('raw: ' + raw);
var params = {
userId: user_id,
resource: { 'raw': raw}
};
var headers = {
"HTTP-Version": "HTTP/1.1",
"Content-Type": "application/json",
"Authorization": "Bearer " + oauth2token
};
var options = {
headers: headers,
url: "https://www.googleapis.com/gmail/v1/users/me/messages/send",
method: "POST",
params: params
};
request(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
context.log(body);
}
if (error) {
context.log(error);
}
else {
context.log(response);
}
})
}