google API calendar watch doesn't work but channel is created

 ̄綄美尐妖づ 提交于 2019-12-11 01:46:38

问题


I try to listen on my calendar change events (google-apps/calendar/v3/reference/events/watch).

I did everything from Google console side, domains - OK, everything is verified and I succeeded to create channel. Also i succeeded to get sync message with right headers (see below). From docs:

Sync message

After creating a new notification channel to watch a resource, the Google Calendar API sends a sync message to indicate that notifications are starting. The X-Goog-Resource-State HTTP header value for these messages is sync. Because of network timing issues, it is possible to receive the sync message even before you receive the watch method response.

That mean that notifications are starting

However when I change something in snaggs@comp.com account - nothing happens, no request sends to callback : 'https://dev-api.mycompany/google-watch/'

This is my working code:

var google = require('googleapis');
var googleAuth = require('google-auth-library');
var _ = require('underscore-node');


var uuid = require('node-uuid');

  // ......

                     var channel_id = uuid.v1();


                        _auth.credentials = {
                            access_token: _token.access_token,
                            token_type: _token.token_type,
                            refresh_token: _token.refresh_token,
                            expiry_date: _token.expiry_date
                        };

                        var data = {
                            auth: _auth,
                            calendarId: _token.provider_email, 
                            singleEvents: true,
                            orderBy: 'startTime',
                            resource: {
                                id: channel_id,
                                token: 'email='+_token.provider_email,
                                address: 'https://dev-api.mycompany/google-watch/',
                                type: 'web_hook',
                                params: {
                                    ttl: '36000'
                                }
                            }

                        };

                        calendar.events.watch(data, function (err, response) {
                            if (err) {
                                console.error('The API returned an error: ' + err);
                                 return;
                            }
                        });

When I start above mentioned snippets of code i get response:

{
  "kind": "api#channel",
  "id": "277fa000-d4b6-12e5-ab58-e7afaf85ea65",
  "resourceId": "C7vFL07CYfqaHy3vDss4qugWDfk",
  "resourceUri": "https://www.googleapis.com/calendar/v3/calendars/snaggs@comp.com/events?orderBy=START_TIME&singleEvents=true&alt=json",
  "token": "email=snaggs@comp.com",
  "expiration": "1455667451000"
}

And in 'https://dev-api.mycompany/google-watch/' URL I get sync message regards to documents, like (See google-apps/calendar/v3/push):

{
  "host": "dev-api.mycompany",
  "accept": "*/*",
  "accept-encoding": "gzip,deflate",
  "user-agent": "APIs-Google; (+https://developers.google.com/webmasters/APIs-Google.html)",
  "x-goog-channel-expiration": "Tue, 16 Feb 2016 22:44:51 GMT",
  "x-goog-channel-id": "277fa000-d4b6-12e5-ab58-e7afaf85ea65",
  "x-goog-channel-token": "email=snaggs@comp.com",
  "x-goog-message-number": "1",
  "x-goog-resource-id": "C7vFL07CYfqaHy3vDss4qugWDfk",
  "x-goog-resource-state": "sync",
  "x-goog-resource-uri": "https://www.googleapis.com/calendar/v3/calendars/snaggs@comp.com/events?orderBy=START_TIME&singleEvents=true&alt=json",
  "x-forwarded-for": "56.102.7.132",
  "x-forwarded-port": "443",
  "x-forwarded-proto": "https",
  "content-length": "0",
  "connection": "keep-alive"
}

but not exists message

Do I miss something?

please help,


回答1:


We have been using Push Notifications for a few years and noticed that for the last 24 hours we did not receive any notifications across several thousand calendars.

Like you we can create/stop a channel but no notifications are received for changes as normal.

As of about an hour ago we are receiving them again. Please try your channel again as it may be a glitch on the Google Push side of things that has been resolved.



来源:https://stackoverflow.com/questions/35434828/google-api-calendar-watch-doesnt-work-but-channel-is-created

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!