javascript - 谷歌日历API观看JavaScript

标签 javascript google-api google-calendar-api

我目前正在使用 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/

相关文章:

javascript - 创建具有可选属性的 JS 对象,具体取决于它们的定义

VB.Net Google Page Speed Api 如何将策略更改为移动设备

google-api - Gmail API - 有没有一种方法可以按 w.r.t. 的排序顺序列出邮件?接收时间?

android - 使用日历 API 摆脱 Android 日历事件中的 "Attending?"

javascript - float 粘性侧边栏未按预期工作

javascript - PHPSESSID从B域到A域在Chrome和Firefox上使用,而不是在Safari和IE上使用

javascript - 动态调整浏览器窗口大小填充 Canvas

php - Google Geolocation API - 您已超出此 API 的每日请求配额

javascript - 像 Google 日历中一样的表单对话框

objective-c - 为什么我的任何 GDataEntryCalendarEvent 中都没有时间?