我目前正在使用 google calendar api 并尝试在 javascript 中编写一个函数,该函数使用 calendar.events.watch
函数,以便在用户日历中有更新时进行更新< em>(取消、创建或修改)。
我正在尝试查看我获得的信息,以便了解该服务是否与我的需求相关 - 了解是否发生了更改,甚至发生了什么更改。
我正在打开一个 channel 并提供数据,但是当我更改日历时,我没有收到任何响应,如下所示: https://developers.google.com/google-apps/calendar/v3/reference/events/watch
这是我写的函数:
function watchEvents(token) {
var calendar = google.calendar('v3');
var oauth2ClientPromise = createAuthObject(token);
console.log('step 1')
return oauth2ClientPromise
.then(function (authObject){
console.log('step 3')
return Q.nfcall(calendar.events.watch, {
auth: authObject,
calendarId: '*I put here my email*',
singleEvents: true,
orderBy: 'startTime',
resource:{
id: channel_id,
token: 'email=' + '* placed my email*',
type: 'web_hook',
address: '*placed my address*',
params: {
ttl: '36000'
}
}
});
})
.catch(function(err) {
console.log('step 2');
});
}
我运行了代码:
calendar.watchEvents(token_parsed).then((result)=>console.log("result"))
.catch(err=>console.log(err));
我没有收到任何错误,并且它输入了我的“步骤 1”和“步骤 3”标志,但是当我更改日历中的事件时,我没有收到任何通知。
这是我在控制台中得到的:
步骤 1 监听端口 8080 的示例应用程序! 步骤3 结果
有谁知道我应该从 API 获得什么样的信息?看起来怎么样?我的为什么不起作用?
最佳答案
但是当我更改日历中的事件时,我没有收到任何消息 通知
Making watch requests 通过向资源的监视方法发送 POST 请求来启用,如指南中所述。
另请注意:
"Each notification channel is associated both with a particular user and a particular resource (or set of resources). A watch request will not be successful unless the current user owns or has permission to access this resource."
示例
开始监视给定日历上事件集合的更改:
POST https://www.googleapis.com/calendar/v3/calendars/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="523f2b0d31333e373c36332012353f333b3e7c313d3f" rel="noreferrer noopener nofollow">[email protected]</a>/events/watch
Authorization: Bearer auth_token_for_current_user
Content-Type: application/json
{
"id": "01234567-89ab-cdef-0123456789ab", // Your channel ID.
"type": "web_hook",
"address": "https://sampledomain.com/notifications", // Your receiving URL.
...
"token": "target=myApp-myCalendarChannelDest", // (Optional) Your channel token.
"expiration": 1426325213000 // (Optional) Your requested channel expiration time.
}
}
您可以从官方指南中阅读更多内容,包括 Receiving Notifications tuts。
关于javascript - 谷歌日历API观看JavaScript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41001070/