简体   繁体   English

HTTP GET:通过Google Calendar API v3获取Google Calendar事件列表-无效的密钥错误

[英]HTTP GET: Get Google Calendar Event List via Google Calendar API v3 - invalid key error

I was using an HTTP GET action on Tasker on Android 4.4 for quite some time now in order to get my future google calendar events. 我在Android 4.4上的Tasker上使用HTTP GET操作已有一段时间,以获取将来的Google日历事件。 This task no longer works due to Google shutting down the v2 API. 由于Google关闭了v2 API,因此该任务不再起作用。

For the API v3 an authentification is needed. 对于API v3,需要进行身份验证。 I tried to get a client key from the developer console. 我试图从开发人员控制台获取客户端密钥。 I created a new project and activated the calendar API for it. 我创建了一个新项目,并为此激活了日历API。 I then created a new client ID and do have this client ID with its corresponding key. 然后,我创建了一个新的客户端ID,并确实具有此客户端ID及其对应的密钥。 How can I get a list of my (future) events from my personal Google calendar via HTTP GET and this authentification information? 如何通过HTTP GET和我的身份验证信息从我的个人Google日历中获取(未来)事件的列表? I'm trying to use: 我正在尝试使用:

https://www.googleapis.com/calendar/v3/calendars/my_calendar_ID/events?singleEvents=true&key=my_client_key https://www.googleapis.com/calendar/v3/calendars/my_calendar_ID/events?singleEvents=true&key=my_client_key

This returns an error: 这将返回错误:

{
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "keyInvalid",
    "message": "Bad Request"
   }
  ],
  "code": 400,
  "message": "Bad Request"
 }
}

What am I doing wrong? 我究竟做错了什么? Thanks in advance! 提前致谢!

Usually this error is thrown when the key used in the request is invalid. 通常,当请求中使用的密钥无效时,会引发此错误。 In the request you have to use the public key not the client secret(when you want to send the API key). 在请求中,您必须使用公共密钥而不是客户端密钥(要发送API密钥时)。 Here is the link for the documentation on how to get the public key to your application. 这是有关如何获取应用程序公钥的文档的链接

Also,here is the link for documentation about the HTTP request for events get request. 另外,这是有关事件的HTTP请求get请求的文档的链接

To anyone trying to achieve the same and who's not in the need to use API v3 at any cost: 对于任何想要达到相同目的并且不需要使用API​​ v3的人:

There is still an option to get future events with a request similar to API v2. 仍然可以通过类似于API v2的请求来获取将来的事件。 Therefore, use the private XML-code from the calendar settings and add the parameters you need. 因此,请使用日历设置中的专用XML代码并添加所需的参数。 Eg: 例如:

HTTP GET http://www.google.com/calendar/feeds/your_email/private-validation/basic?futureevents=true&max-results=1&singleevents=true&orderby=starttime&sortorder=ascending

I could not find any up-to-date documentation from Google about this but it's working. 我找不到来自Google的任何有关此文档的最新文档,但是它正在运行。 The main difference to API v2 is the "/basic?" API v2的主要区别是“ / basic?” at the end instead of the old "/full?". 在末尾而不是旧的“ / full?”。 Otherwise most parameters seem to work fine. 否则,大多数参数似乎都可以正常工作。

futureevents=true - only shows future events
max-results=integer - only show integer number of results
singleevents=true - handly reoccuring events as single events
orderby=starttime - sort results by their starting time instead of last update
sortorder=ascending - well, sort order

"printpretty" seems not to be supported anymore. 似乎不再支持“ printpretty”。 Also, the timestamp has a different look now. 另外,时间戳现在看起来有所不同。 But still, all the information needed is included. 但是,仍然包括了所有需要的信息。

The example above shows the request for the next event in the calendar. 上面的示例显示了对日历中下一个事件的请求。 This may be extended to multiple events (eg max-results=5). 这可以扩展到多个事件(例如max-results = 5)。 The other parameters are needed to show up the next events as expected instead of some seemingly random events. 需要其他参数来显示预期的下一个事件,而不是某些看似随机的事件。 The problem with this method is of course that your private adress is used in the request which may be insecure in comparison to API v3. 这种方法的问题当然是请求中使用了您的私人地址,与API v3相比,这可能是不安全的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM