2017-04-13 12 views
1

ウォッチチャンネルを停止すると、エラーで応答していませんが、一晩配信を許可しても停止しています。私はまだ1つのカレンダーリストの変更について5つの通知を受けています。ときどき6.時々3.散発的です。また、8秒後に同じアクションの通知を2回受け取ります。時々6秒。時にはランダムなカウントを持つ3番目のセット。また、散発的です。ウェブブラウザ経由で作成された1つのカレンダーに合計10個のユニークなメッセージを受信しました。GoogleカレンダーAPIウォッチチャンネルが停止していません

答えて

0

文書に記載されているChannels.stopを使用してください。リクエストのボディに次のデータを供給:

{ 
    "id": string, 
    "resourceId": string 
} 

idは、チャネルIDあなたcreated your watch requestです。リソースIDも同じです。

この詳細については、SO threadおよびthis github forumをお読みください。

+0

我々はRESTfulなAPIを使用して、これを試みてきたし、我々が正常にチャネルを停止することができません。チャンネルを停止する前に、作成後一定の待機時間はありますか? – TaskBasic

0

特定のカレンダーリソースで無限の監視リクエストを実行できますが、Googleでは常に同じカレンダーの同じカレンダーリソースIDを返しますが、リクエストで生成するUuidは異なるため、あなたが作成したウォッチリクエストごとに複数の通知を受け取ります。特定のカレンダーリソースからすべての通知を停止する方法の1つは、通知をリスンし、通知ヘッダーから「x-goog-channel-id」および「x-goog-resource-id」を取り出し、Channels.stop要求で使用することです。 UUIDまたはリソースIDがすでに存在する場合、はい、再びそのリソースIDの時計の要求を実行しない場合

{ 
    "id": string, 
    "resourceId": string 
} 

あなたは時計の要求を実行するたびに、あなたは(もし、応答からデータを永続化し、チェックする必要があります複数の通知を受け取ることは望ましくありません)。

app.post("/calendar/listen", async function (req, res) { 
    var pushNotification = req.headers; 
    res.writeHead(200, { 
     'Content-Type': 'text/html' 
    }); 
    res.end("Post recieved"); 
    var userData = await dynamoDB.getSignInData(pushNotification["x-goog-channel-token"]).catch(function (err) { 
     console.log("Promise rejected: " + err); 
    }); 
    if (!userData) { 
     console.log("User data not found in the database"); 
    } else { 
     if (!userData.calendar) { 
      console.log("Calendar token not found in the user data object, can't perform Calendar API calls"); 
     } else { 
      oauth2client.credentials = userData.calendar; 
      await calendarManager.stopWatching(oauth2client, pushNotification["x-goog-channel-id"], pushNotification["x-goog-resource-id"]) 
     } 
    } 
}; 

calendarManager.js

module.exports.stopWatching = function (oauth2client, channelId, resourceId) { 
    return new Promise(function (resolve, reject) { 
     calendar.channels.stop({ 
      auth: oauth2client, 
      resource: { 
       id: channelId, 
       resourceId: resourceId 
      } 
     }, async function (err, response) { 
      if (err) { 
       console.log('The API returned an error: ' + err); 
       return reject(err); 
      } else { 
       console.log("Stopped watching channel " + channelId); 
       await dynamoDB.deleteWatchData(channelId) 
       resolve(response); 
      } 
     }) 
    }) 
} 
関連する問題