Gmail API users.watch - 没有historyId的详细信息 [英] Gmail API users.watch - no details for historyId

查看:99
本文介绍了Gmail API users.watch - 没有historyId的详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已成功设置Google Pub / Sub以使用Gmail API Watch功能,如下所述: https://developers.google.com/gmail/api/guides/push 观看我的Gmail账户中的INBOX标签。



一旦有新消息到达我立即以有效格式获得推送通知,例如:

  {message:
{data:'.... ...',
属性:{},
message_id:'1248700053943'},
订阅:'.....'}

在base64解码数据后,我收到了email和historyId。然后,按照建议,我请求gmail.users.history.list API(通过API控制台),并将startHistoryId设置为推送通知中的historyId。然后在没有任何详细信息的情况下获得空的响应:

  GET https://www.googleapis.com/gmail/v1/users / me / history?startHistoryId = 4658879& key = {YOUR_API_KEY} 
200 OK
- 显示标题
{
historyId:4658894
}

因此,来自通知的historyId似乎不是有效的。
似乎Gmail users.watch API无法正常工作,并且发送了错误的historyId,或者我只是缺少了什么?

解决方案

看起来我误解了users.history.list的工作原理,流程应该如下所示:


  1. 记住historyId来自users.watch请求的响应。


  2. 在推送通知中调用users.history.list与以前记住的historyId作为startHistoryId,而不是通知中的新通知,并获取最近更改的列表。


  3. 从通知中记住historyId,然后转到2。 >

    如果我们查看对users.history.list的任何调用的响应,historyId将始终存在,它是最新历史记录更改的标记。推送通知带来最新的historyId,所以如果我们请求users.history.list(如问题中),我们得到了空的历史数组,并且服务器从响应中删除了这个空的历史字段,这就是为什么我们得到这个:

      {
    historyId:4658894
    }



    但不是这样:

      { 
    history:[],
    historyId:4658894
    }

    同步指南中提供了更多详细信息: https://开发人员。 google.com/gmail/api/guides/sync#partial



    因此,我们无法轻易获取从推送通知到INBOX的新消息的详细信息,需要处理历史挖掘和同步才能找到它。

    I have successfully set up Google Pub/Sub to use Gmail API Watch feature as described here: https://developers.google.com/gmail/api/guides/push to watch INBOX label in my gmail account.

    Once new message arrive I instantly get a push notification in valid format like:

    { message: 
        { data: '.......',
        attributes: {},
        message_id: '1248700053943' },
    subscription: '.....' }
    

    After I base64decode data I get email and historyId. Then, as suggested, I request gmail.users.history.list API (via API console) with startHistoryId set to the historyId from the push notification. And then get just empty response without any details:

    GET https://www.googleapis.com/gmail/v1/users/me/history?startHistoryId=4658879&key={YOUR_API_KEY}
    200 OK
    - Show headers 
    {
     "historyId": "4658894"
    }
    

    So historyId from a notification does not seems valid. Seems Gmail users.watch API is not working properly, and sends wrong historyId, or I'm just missing something?

    解决方案

    Looks like I misunderstood how users.history.list works, and the flow should be something like described below:

    1. Remember historyId from the response of users.watch request.

    2. On push notification call users.history.list with previously remembered historyId as startHistoryId instead of new one from notification, and get list of recent changes.

    3. Remember historyId from notification, and goto 2.

    If we look on the response of any call to users.history.list, historyId is always present, it's a marker of latest history change. Push notification brings latest historyId, so if we request users.history.list with it (as in the question), we got empty array of history, and the server drops this empty "history" field from the response, that's why we get this:

    {
     "historyId": "4658894"
    }
    

    But not this:

    {
     "history": [ ],
     "historyId": "4658894"
    }
    

    More details provided in sync guide: https://developers.google.com/gmail/api/guides/sync#partial

    So we can't easily get details of the new message arrived to INBOX from push notification, and need to deal with history mining and synchronization to find it.

    这篇关于Gmail API users.watch - 没有historyId的详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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