2016-02-16 69 views
1

我嘗試收聽我的日曆更改事件(google-apps/calendar/v3/reference/events/watch)。谷歌API日曆手錶不起作用,但渠道創建

我做了一切,從谷歌控制檯端,域 - 好吧,一切都驗證,我成功創建頻道。另外我成功得到sync帶有正確標題的消息(見下文)。從文檔:

同步消息

創建一個新的通知要觀看的頻道資源後, 谷歌日曆API發送sync消息表明 通知開始。這些消息的X-Goog-Resource-State HTTP頭 值是同步的。由於網絡時間問題,即使在收到 監視方法響應之前,它也可能會收到同步消息。

這意味着notifications are starting

然而,當我改變的東西在[email protected]帳戶 - 什麼也沒有發生,沒有請求發送到回調'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]/events?orderBy=START_TIME&singleEvents=true&alt=json", 
    "token": "[email protected]", 
    "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": "[email protected]", 
    "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]/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消息

難道我錯過了什麼?

請大家幫忙,

回答

2

我們一直在使用推送通知了幾年,發現在過去24小時內,我們沒有跨越幾千年的日曆收到任何通知。

和我們一樣,我們可以創建/停止頻道,但沒有收到任何通知。

大約一個小時前,我們再次收到它們。請再次嘗試您的頻道,因爲它可能是已解決事情的Google Push方面的小故障。

+0

好的,謝謝,我明天再試 – snaggs

+0

是的,你說的對,它突然開始工作。 – snaggs

+0

是一個Outage @ Google。它通常非常可靠。您需要針對應用程序中的更改構建一些輪詢以迎合PUSH失敗的情況。 – PNC