我尝试监听我的日历更改事件(谷歌应用程序/日历/v3/参考/事件/手表 https://developers.google.com/google-apps/calendar/v3/reference/events/watch).
我从 Google 控制台方面做了所有事情,域 - 好的,一切都经过验证,我成功创建了频道。我也成功得到了sync
带有正确标题的消息(见下文)。来自文档:
同步消息
创建新的通知通道来监视资源后,
Google Calendar API 发送一条同步消息来表明
通知正在开始。 X-Goog-Resource-State HTTP 标头
这些消息的值是同步的。由于网络时序问题,
即使在您收到同步消息之前也可以接收同步消息
观察方法响应。
这意味着notifications are starting
但是当我改变一些东西时[email protected] /cdn-cgi/l/email-protection
帐户 -什么也没发生,没有请求发送到回调 : '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/[email protected] /cdn-cgi/l/email-protection/events?orderBy=START_TIME&singleEvents=true&alt=json",
"token": "[email protected] /cdn-cgi/l/email-protection",
"expiration": "1455667451000"
}
And in 'https://dev-api.mycompany/google-watch/'
我得到的网址sync
关于文档的消息,例如(参见谷歌应用程序/日历/v3/推送 https://developers.google.com/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 protected] /cdn-cgi/l/email-protection",
"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/[email protected] /cdn-cgi/l/email-protection/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
我错过了什么吗?
请帮忙,