无法使用Google API提取假期

问题描述 投票:0回答:2

作为我正在开发的应用程序的一部分,我想提供假期清单。我正在尝试使用Google API来执行此操作。在编写代码之前,我只想看看返回的JSON是什么样的。

我在Google中设置了一个帐户,获得了API密钥,并设置为使用Google Calendar API。我对获取假期列表所需的HTML进行了研究,但似乎无法使其正常工作。我浏览了所有Calendar API文档,但未找到有关获取假期列表的任何信息。这是我尝试过的一些URL,以及收到的响应。我在网上(主要是在这里)找到了所有这些URL示例。我已经删除了我的API密钥。

https://www.googleapis.com/calendar/v3/calendars/en.uk%40holiday.calendar.google.com/events?key=myKey

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

https://www.googleapis.com/calendar/v3/calendars/en.sa%[email protected]/events?key=myKey

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

https://www.googleapis.com/calendar/v3/calendars/en.uk%40holiday.calendar.google.com/events?key=myKey

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

https://www.googleapis.com/calendar/v3/calendars/[email protected]/events?key=myKey

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

https://www.googleapis.com/calendar/v3/calendars/en.usa#[email protected]/events?key=myKey

{
    "error": {
        "errors": [
        {
            "domain": "global",
            "reason": "required",
            "message": "Login Required",
            "locationType": "header",
            "location": "Authorization"
        }
        ],
        "code": 401,
        "message": "Login Required"
    }
}

Google看到了我的请求,这些都是错误。

enter image description here

似乎我在网上找到的URL一次可以使用,但似乎不再可用。

有关使用方法是否有任何更新?

更新:我尝试了以下答案的信息,现在我明白了:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Login Required",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Login Required"
 }
}

我在Events:List API参考的“尝试使用此API”部分中尝试en.danish#[email protected],并且能够获取日期的JSON。我不明白为什么它可以在Try This API中使用,但不能通过url使用。我尝试过的最新网址:

https://www.googleapis.com/calendar/v3/calendars/en.danish#[email protected]/events?key=myKey

google-api google-calendar-api
2个回答
0
投票

当前api中似乎有错误。应使用API​​密钥访问公共api,不再需要身份验证

🐞bug report here

错误验证信息

GET https://www.googleapis.com/calendar/v3/calendars/en.danish%23holiday%40group.v.calendar.google.com?key={YOUR_API_KEY}

响应:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Login Required",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Login Required"
 }
}

如果您使用Oauth2并对自己进行身份验证,则会得到

{

 "kind": "calendar#calendar",
 "etag": "\"2IG_UfzQLHbZ3_DsNnNPPvIpYxU/iF_yglNpjvUgQba3YfGrk5JFgq4\"",
 "id": "en.danish#[email protected]",
 "summary": "Holidays in Denmark",
 "timeZone": "Europe/Copenhagen",
 "conferenceProperties": {
  "allowedConferenceSolutionTypes": [
   "eventHangout"
  ]
 }
}

0
投票

我能够通过对公共日历ID中的#@进行网址编码来解决此问题。

就我而言:

en.new_zealand#[email protected]

成为:

en.new_zealand%23holiday%40group.v.calendar.google.com/events

直到我这样做之前,我一直收到401错误。

© www.soinside.com 2019 - 2024. All rights reserved.