[英]how to get read and unread message list using gmail api javascript
[英]Gmail REST API - Mark message as read
我正在嘗試使用Gmail REST API將郵件標記為已讀。
$('#markGmailRead').click(function(){
var request = $.ajax({
type: 'POST',
dataType: 'json',
headers: { "Authorization": "Bearer <<ACCESS KEY>>",
"Content-Type": "application/json"},
url: 'https://www.googleapis.com/gmail/v1/users/me/messages/<<MESSAGEID>>/modify',
data: {"addLabelIds": ["UNREAD"]}
})
request.done(function(data){
// when the Deferred is resolved.
console.log(data);
})
request.fail(function(){
// when the Deferred is rejected.
console.log('fail');
})
})
這導致返回以下json:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "parseError",
"message": "Parse Error"
}
],
"code": 400,
"message": "Parse Error"
}
}
還有其他人經歷過這個嗎? 我不知道可能導致這種情況的原因。
我能夠弄清楚這一點並讓它發揮作用。 唯一的區別是將數據字符串化如下:
data: JSON.stringify({"removeLabelIds":["UNREAD"]}),
進行此更改使其工作。
嘗試在代碼中添加ContentType =“application / json; charset = UTF-8”。 另外,請檢查此鏈接以獲取有關錯誤的詳細信息。
如果您仍然看到錯誤,請告訴我。
我在Meteor中遇到同樣的問題。 問題是我在'params'屬性中傳遞了removeLableIds。 更改為“數據”屬性有效,即
var apiUrl = "https://www.googleapis.com/gmail/v1/users/me/messages/" + messageID + "/modify"; var result = HTTP.post( apiUrl, { data: { "removeLabelIds": ["INBOX"] }, headers:{ "content-type":"application/json ; charset=UTF-8", "Authorization": "Bearer " + tokens.accessToken } });
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.