2013-10-15 31 views
4

我正在嘗試進行Google日曆推送通知API調用(https://developers.google.com/google-apps/calendar/v3/push)。我想出瞭如何進行日曆列表調用。所以,我相信我的Oauth 2.0身份驗證片正在工作。我猜我需要指定推送通知電話是POST。這裏是我的代碼:如何使用google-api-nodejs-client進行POST API調用?

var params = { calendarId: calendarId, 
       id: 'my-unique-id-00001', 
       type: "web_hook", 
       address: "https://mydomain.com/notifications" }; 
    client 
    .calendar.events.watch(params) 
    .withAuthClient(authClient) 
    .execute(callback); 

我不斷收到此錯誤信息:

{錯誤: [{域: '全球性', 原因: '必要', 消息: 'entity.resource' , debugInfo:'com.google.api.server.core.Fault:ImmutableErrorDefinition {base = REQUIRED,category = USER_ERROR,cause = com.google.api.server.core.Fault:Builder {base = REQUIRED,...

+0

你是否設法找出這一個?我遇到類似的問題。 – sheldonbaker

+0

你知道你的請求的內容類型是什麼嗎?我曾經看到過這個錯誤!= application/json – jtmoulia

+0

奇怪的是,我使用google提供的google-api-ruby-client,我仍然需要爲應用程序/ json設置Content-Type頭以便做觀看請求。謝謝! – paf0

回答

2

當我試圖使用Google Drive API觀看某些內容時,遇到了同樣的問題。事實證明,一些參數需要在響應主體中。

在你的情況,我認爲calendarId需要是一個路徑參數,其他需要在請求主體。像這樣的東西應該能工作

var pathParams = { calendarId: calendarId }; 
var bodyParams = { 
    id: 'my-unique-id-00001', 
    type: 'web_hook', 
    address: 'https://mydomain.com/notfications' 
}; 
client 
    .calendar.events.watch(pathParams, bodyParams) 
    .withAuthClient(authClient) 
    .execute(callback);