Gmail REST API - 将邮件标记为已读 [英] Gmail REST API - Mark message as read

查看:101
本文介绍了Gmail REST API - 将邮件标记为已读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to use the Gmail REST APIs to mark a message as read.

$('#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:

This results in the following json returned:

{
 "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.

这篇关于Gmail REST API - 将邮件标记为已读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆