[英]Gmail REST API - Mark message as read
I am trying to use the Gmail REST APIs to mark a 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');
})
})
This results in the following json returned: 这导致返回以下json:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "parseError",
"message": "Parse Error"
}
],
"code": 400,
"message": "Parse Error"
}
}
Has anyone else experienced this? 还有其他人经历过这个吗? I'm at a loss as to what may be causing this. 我不知道可能导致这种情况的原因。
I was able to figure this out and get it working. 我能够弄清楚这一点并让它发挥作用。 The only difference to be made was to stringify the data like so: 唯一的区别是将数据字符串化如下:
data: JSON.stringify({"removeLabelIds":["UNREAD"]}),
Making this change made it work. 进行此更改使其工作。
I had the same problem doing this in Meteor. 我在Meteor中遇到同样的问题。 The problem was I was passing the removeLableIds in the 'params' attribute. 问题是我在'params'属性中传递了removeLableIds。 Changing to the 'data' attribute worked, ie 更改为“数据”属性有效,即
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.