0

我需要从日历 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)

4

2 回答 2

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"
}

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

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

日历列表.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

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

于 2017-05-08T07:58:16.517 回答
0

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

请参阅此链接

于 2020-08-12T20:52:29.147 回答