Gmail REST API – 将邮件标记为已读

我正在尝试使用Gmail REST API将邮件标记为已读。

$('#markGmailRead').click(function(){ var request = $.ajax({ type: 'POST', dataType: 'json', headers: { "Authorization": "Bearer <>", "Content-Type": "application/json"}, url: 'https://www.googleapis.com/gmail/v1/users/me/messages/<>/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 } }); 
    Interesting Posts