0

我需要從日曆ID中獲取日曆名稱。我已提供正確的Google日曆ID,並通過api發送,以獲取日曆詳細信息並獲取日曆名稱。無法通過API使用日曆ID獲取Google日曆名稱

https://www.googleapis.com/calendar/v3/calendars/en.indian#[email protected] 

    Method type: GET 
    Content-Type: application/json 
    Authorization: Bearer <latest access_token> 

我使用Google Calendar API在線檢查了它,它工作正常。但是當我通過郵遞員或在我的Java代碼中傳遞時,接收到以下json。當我給像en.indian#[email protected](Holidays in India)

+0

calendarlist的corect調用是https://www.googleapis.com/calendar/v3/users/me/calendarList,它將顯示您已安裝在日曆列表中的日曆。你不能通過它的日曆。你究竟想要做什麼? – DaImTo

+0

我想從日曆ID獲取日曆名稱en.indian#[email protected] –

+0

請修改您的問題並加入http://stackoverflow.com/help/mcve – DaImTo

回答

1

默認日曆ID的要獲取有關日曆的信息,你應該使用

Calendar.get返回元數據日曆只發生

{ 
     "error": { 
     "errors": [ 
      { 
      "domain": "global", 
      "reason": "notFound", 
      "message": "Not Found" 
      } 
     ], 
     "code": 404, 
     "message": "Not Found" 
     } 
    } 

此錯誤。

請求(注訪問令牌):

GET https://www.googleapis.com/calendar/v3/calendars/en.indian#[email protected]?access_token=youraccesstoken

響應

{ 
"kind": "calendar#calendar", 
"etag": "\"fBXC91rAg76NkSpaCdEoUEir1ww/pR1e1Z3gR0361TBF8mRGGxGD_VM\"", 
"id": "en.indian#[email protected]", 
"summary": "Holidays in India", 
"timeZone": "Europe/Copenhagen" 
} 

此調用需要你來,即使是公共日曆認證肯定。

日曆列表只有在經過身份驗證的用戶已將此日曆添加到日曆列表中時纔有效。

Calendarlist.get

請求

GET https://www.googleapis.com/calendar/v3/users/me/calendarList/en.danish#[email protected]?access_token=youraccesstoken

響應

{ 
"kind": "calendar#calendarListEntry", 
"etag": "\"1442929251602000\"", 
"id": "en.danish#[email protected]", 
"summary": "Holidays in Denmark", 
"timeZone": "Europe/Copenhagen", 
"colorId": "11", 
"backgroundColor": "#fbe983", 
"foregroundColor": "#000000", 
"selected": true, 
"accessRole": "reader", 
"defaultReminders": [] 
} 

授權

此請求需要至少具有以下一個範圍的授權(請閱讀有關身份驗證和授權的更多信息)。

範圍 https://www.googleapis.com/auth/calendar.readonly https://www.googleapis.com/auth/calendar

注:我的日曆是有問題的用戶已經創建日曆列表​​。其他日曆是與用戶共享的日曆列表。

+0

謝謝你的迴應。但是我仍然得到同樣的錯誤。是否有可能我們無法訪問「其他日曆」部分,其中包含「印度的假期」,「美國的假期」等。我們可以在Authorization標頭中提供access_token,而不是在url中提供它本身? –

+0

確保您使用正確的範圍進行了身份驗證?您應該也可以將Authorization Bearer accessToken作爲它的工作頭。 – DaImTo

+0

是的我使用正確的範圍進行了身份驗證,幷包含最新的access_token。結果顯示在Google日曆的「我的日曆」部分下列出的其他日曆中,但「其他日曆」部分中出現錯誤 –