1
我想在我的流星應用程序,它返回下面的錯誤使用Gmail API發送郵件,Gmail發送API,錯誤代碼400流星失敗
Error in calendar insert: Error: failed [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" } }
我曾嘗試以下,
"sendGmail": function(str) {
this.unblock();
var url = "https://www.googleapis.com/gmail/v1/users/me/messages/send";
var encodedMail = new Buffer(str).toString("base64").replace(/\+/g, '-').replace(/\//g, '_');
try {
Meteor.http.post(url, {
'headers' : {
'Authorization': "Bearer " + Meteor.user().services.google.accessToken,
'Content-Type': 'application/json'
},
'body': JSON.stringify({
"raw": encodedMail
})
});
} catch(e){
console.log("Error in calendar insert: " + e);
} finally {
return true;
}
}
傳遞下面字符串值作爲參數:
var str = "Content-Type: text/plain; charset=\"UTF-8\"\n" +
"MIME-Version: 1.0\n" +
"Content-Transfer-Encoding: 7bit\n" +
"to: [email protected]\n" +
"from: [email protected]\n" +
"subject: Meteor test mail\n\n" +
"Hi, this is test mail from meteor application";
Meteor.call('sendGmail', str);
謝謝!數據沒有,但'內容'工作正常:-) – Arun
@阿倫啊,你說得對:)內容是一個純粹的字符串,'數據'接受一個對象,這個對象將被庫製成一個字符串。我更新了答案。 – Tholle