Google calendar v3 Push notification expiry

前端 未结 3 2019
轮回少年
轮回少年 2021-01-03 14:41

I am using Google Calendar Push Notifications. All is working well and I register my channel with no issue. Changes to the calendar result in a notification as expected.

相关标签:
3条回答
  • 2021-01-03 15:10

    by default google keeps channel expiry time for one week, How ever you can set the channel expiry time upto one month by using ttl variable

      EX: body = {
              "id": uuid,
              "type": "web_hook" ,
              "token": "something_unique",
              "address": "web hook url",
              "params": {
                         "ttl" : 864000
                         }
              }
            calendar_service = get_calendar_service(user_email)
            resource = calendar_service.events().watch(calendarId='primary', body=body).execute()
    

    here ttl is in seconds ,and it keeps channel expiry time for 10 days

    0 讨论(0)
  • 2021-01-03 15:13

    I too have been plagued by this apparent bug in the Calendar API. After two days of testing I have uncovered the following:

    1. This bug only seems to manifest when you watch() a calendar using a Service Account (which is always the case for Google Apps Marketplace apps). I only tested watching a secondary calendar, so I can't confirm if the problem exists when watching a primary calendar.

    2. When you include "params": { "ttl" : 172800 } you will get a channel back with an expiration header set for 2 days from now. However, notifications will STOP being sent after 1 hour, indicating the channel is dropped, and that Google Calendar is not correctly respecting the expiration.

    3. If you include "params": { "ttl" : 172800 } and watch() a calendar with a normal access token from a regular oAuth2 flow then the channel is created with the specified expiration AND notifications are sent as expected up until the expiration. This is true whether you are watching a Gmail account's calendar OR a Google App account's calendar - as long as you use regular OAuth2 and NOT a Service Account.

    4. I tried using the undocumented

    -

    body = { "expiration" : MILLISECONDS_SINCE_EPOCH, ....}.
    

    instead of

    body = { "params": { "ttl" : 172800 }, ....}.  
    

    This is what the Google API Python Client Library uses and it had no effect. Channels were created with the correct expiration, but expired after an hour when using a Service Account.

    This is a particularly bad bug because it appears a channel is created correctly, but it expires early and you have no way of verifying what channels are active for a particular resource.

    The only workaround I've figured out so far is to renew every channel after an hour. This is NOT a long-term solution. I will be using over 300,000 API calls per day just to keep channels active, which is a huge chunk of my quota. If things were working correctly I would only need to renew channels at most once a week, not 24 times a day.

    0 讨论(0)
  • 2021-01-03 15:19

    This issue is now fixed - see the following:

    Issue Details

    0 讨论(0)
提交回复
热议问题