谷歌API日历监视不起作用,但创建了频道

时间:2016-02-16 14:12:49

标签: node.js google-api google-api-nodejs-client

我尝试听取我的日历变更事件(google-apps/calendar/v3/reference/events/watch)。

我从谷歌控制台方面做了一切,域名 - 好的,一切都经过验证,我成功创建了频道。此外,我成功获得了带有正确标题的sync消息(见下文)。来自docs:

  

同步讯息

     

创建新的通知渠道以观察资源后,   Google Calendar API会发送同步消息以指明该消息   通知正在开始。 X-Goog-Resource-State HTTP标头   这些消息的值是同步的。由于网络计时问题,它   甚至可以在收到之前收到同步消息   观看方法回应。

这意味着notifications are starting

但是当我在snaggs@comp.com帐户中更改内容时 - 没有任何反应,没有请求发送到回调'https://dev-api.mycompany/google-watch/'

这是我的工作代码:

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;
                            }
                        });

当我开始上面提到的代码片段时,我得到了回复:

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

'https://dev-api.mycompany/google-watch/'网址中,我收到了sync关于文档的消息,例如(请参阅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"
}

但不是exists消息

我错过了什么吗?

请帮忙,

1 个答案:

答案 0 :(得分:2)

我们一直使用Push Notifications几年,并注意到过去24小时内我们没有收到数千个日历的任何通知。

与我们一样,我们可以创建/停止频道,但不会收到正常更改的通知。

大约一个小时前,我们又收到了他们。请再次尝试使用您的频道,因为Google推送方面的问题可能已经解决了。