【问题标题】:Google javascript API library - Calendar watch notificationsGoogle javascript API 库 - 日历手表通知
【发布时间】:2013-10-11 14:27:55
【问题描述】:

我正在尝试使用 JS 客户端库订阅日历事件通知,如下所示:

gapi.client.load('calendar', 'v3', function () {
            var request = gapi.client.calendar.events.watch({
                'calendarId': cl.gCalendarID,
                'id': unid,
                'type': "web_hook",
                'address': {my url here}
            });
            request.execute(function (resp) {
                console.log(resp);
            });
        });

但我只是不断收到 400 条“Entity.Resource”的无益消息返回

在响应的数据对象中我得到Domain:global, Message: Entity.Resource, reason: Required"

我已经通过 oauth2 进行了身份验证,并且我已通过我的 Google 帐户授予访问权限,并且我可以成功检索日历列表,并且我正在从日历中检索事件,但是这种订阅手表的方法不起作用?请帮助我在 Google 上找不到任何关于此的内容。

【问题讨论】:

  • 您知道您的请求的内容类型是什么吗?我在 != application/json 时看到过这个错误

标签: javascript calendar google-api


【解决方案1】:
Instead of this:


 var request = gapi.client.calendar.events.watch({
                'calendarId': cl.gCalendarID,
                'id': unid,
                'type': "web_hook",
                'address': {my url here}
            });

你使用这个语法:

calendar.events.watch({
            auth: auth,
                resource: {
                    id: "12345",
                    type: 'web_hook',
                    address: {mu url here}
                 },
                calendarId: 'primary' 

            }, function(err, response) {
                if (err) {
                    logger.MessageQueueLog.log("info","index.js:- watchnotification(),Error in Watch Notification: " + err);

                } else {          
                   logger.MessageQueueLog.log("info","index.js:- watchnotification(), Notification : " + JSON.stringify(response));           

                }
            });

希望它会起作用。

【讨论】:

    【解决方案2】:

    您需要在向日历 API 发出的请求中传递令牌值,以区分您的请求,如下所示

    {
      "id": string,
      "token": string,
      "type": string,
      "address": string,
      "params": {
      "ttl": string
     }
    }
    

    更多参考,请参考

    Google Calendar API

    【讨论】:

    • 这对我没有帮助。令牌是可选的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-18
    • 2015-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-12
    相关资源
    最近更新 更多