我正在尝试使用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"]}),
进行此更改即可使其生效。