我尝试监听我的日历更改事件 ( 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/