【问题标题】:Cannot fetch the Google Calendar name through API using Calendar ID无法使用日历 ID 通过 API 获取 Google 日历名称
【发布时间】:2017-05-08 07:27:58
【问题描述】:

我需要从日历 ID 中获取日历名称。我提供了正确的 Google 日历 ID 并通过 api 发送它以获取日历详细信息并获取日历名称。

    https://www.googleapis.com/calendar/v3/calendars/en.indian#holiday@group.v.calendar.google.com

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

我已经在线使用 Google Calendar API 进行了检查,它工作正常。但是当我通过邮递员或在我的 java 代码中传递它时,会收到以下 json。

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

此错误仅在我提供默认日历 ID 时发生,例如 en.indian#holiday@group.v.calendar.google.com(Holidays in India)

【问题讨论】:

标签: google-api google-apis-explorer google-calendar-api


【解决方案1】:

要获取有关您应该使用的日历的信息

Calendar.get 返回日历的元数据。

请求(注意访问令牌):

获取https://www.googleapis.com/calendar/v3/calendars/en.indian#holiday@group.v.calendar.google.com?access_token=youraccesstoken

回应

{
 "kind": "calendar#calendar",
 "etag": "\"fBXC91rAg76NkSpaCdEoUEir1ww/pR1e1Z3gR0361TBF8mRGGxGD_VM\"",
 "id": "en.indian#holiday@group.v.calendar.google.com",
 "summary": "Holidays in India",
 "timeZone": "Europe/Copenhagen"
}

此调用要求您进行身份验证,即使是公共日历也是如此。

只有经过身份验证的用户将此日历添加到日历列表中时,日历列表才会起作用。

Calendarlist.get

请求

获取https://www.googleapis.com/calendar/v3/users/me/calendarList/en.danish#holiday@group.v.calendar.google.com?access_token=youraccesstoken

回应

{
 "kind": "calendar#calendarListEntry",
 "etag": "\"1442929251602000\"",
 "id": "en.danish#holiday@group.v.calendar.google.com",
 "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

注意:我的日历是相关用户创建的日历列表。其他日历是与用户共享的日历列表。

【讨论】:

  • 感谢您的回复。但我仍然得到同样的错误。是否有可能我们无法访问具有“印度假期”、“美国假期”等的“其他日历”部分。我们可以在授权标头中提供 access_token 而不是在 url 中提供自己?
  • 确保您使用正确的范围进行身份验证?您还应该能够将 Authorization Bearer accessToken 作为它可以工作的标头。
  • 是的,我已经通过正确的范围进行了身份验证,并包含了最新的 access_token。结果显示在 Google 日历中“我的日历”部分下列出的其他日历,但在“其他日历”部分出现错误
  • 因此我们无法使用 api 编辑或访问“其他日历”。我们可以吗?
  • 当您调用 CalendarList.list 时,只需添加参数“minAccessRole”并将其设置为“owner”。这样,您只能取回您有权访问的 calendarList。
【解决方案2】:

将 # 转换为 %23。
该 URL 删除了 # 及之后。

请参阅此link。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-04
    • 1970-01-01
    • 2015-01-16
    • 2013-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多