node.js - 谷歌API日历 watch 不起作用,但 channel 已创建

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

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

我从 Google 控制台端、域中完成了所有操作 - 好的,一切都已验证,我成功创建了 channel 。我也成功得到sync带有正确标题的消息(见下文)。来自文档:

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.

这意味着 notifications are starting

但是,当我更改 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0a79646b6d6d794a6965677a24696567" rel="noreferrer noopener nofollow">[email protected]</a> 中的某些内容时帐户 - 没有任何反应,没有请求发送到回调:'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/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ddaeb3bcbabaae9dbeb2b0adf3beb2b0" rel="noreferrer noopener nofollow">[email protected]</a>/events?orderBy=START_TIME&singleEvents=true&alt=json",
  "token": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9cf9f1fdf5f0a1eff2fdfbfbefdcfff3f1ecb2fff3f1" rel="noreferrer noopener nofollow">[email protected]</a>",
  "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": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="92f7fff3fbfeafe1fcf3f5f5e1d2f1fdffe2bcf1fdff" rel="noreferrer noopener nofollow">[email protected]</a>",
  "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/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="afdcc1cec8c8dcefccc0c2df81ccc0c2" rel="noreferrer noopener nofollow">[email protected]</a>/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消息

我错过了什么吗?

请帮忙,

最佳答案

我们使用推送通知已有几年,并注意到在过去 24 小时内,我们没有收到数千个日历中的任何通知。

像您一样,我们可以创建/停止 channel ,但通常不会收到任何更改通知。

大约一个小时前,我们再次收到它们。请重试您的 channel ,因为这可能是 Google Push 方面的问题,但已解决。

关于node.js - 谷歌API日历 watch 不起作用,但 channel 已创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35434828/

相关文章:

javascript - Nodejs Http Server api 执行流程请解释一下?

node.js - 从 Node 查询 MariaDB 时结果中的字符编码不一致

node.js - 在 Go 中,编写非阻塞代码有意义吗?

android - GoogleAuthToken 在没有范围访问权限的情况下返回访问 token 并抛出错误使用限制

javascript - 如何在 sequelize v6 中删除自动创建的列 ID?

reactjs - 使用 React 和 google API 将评论放入 google 评论中

javascript - 如何从应用程序脚本中使用 googleapis

node.js - 在多个帐户之间切换时,Gdrive API V3 出现 403 错误

javascript - 按名称打开电子表格,如果未找到则创建新电子表格

node.js - 从 Google 云端硬盘中的特定文件夹中列出其中的文件夹和文件