Pergunta

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.

The issue is however that after an hour or so the notifications expire.

In reading the documentation I cannot work out why there is an expiry given that I am not specifying one.

When the channel is registered the response actually states an expiry date of 1 week from when I register the channel - e.g. Fri, 31 Jan 2014 03:23:59 GMT.

This is not however what I am experiencing.

Does somebody know what the prescribed behaviour is here.

Thanks for your Help

Paul

Foi útil?

Solução

This issue is now fixed - see the following:

Issue Details

Outras dicas

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

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top