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

2k views Asked by At

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. This task no longer works due to Google shutting down the v2 API.

For the API v3 an authentification is needed. I tried to get a client key from the developer console. I created a new project and activated the calendar API for it. I then created a new client ID and do have this client ID with its corresponding key. How can I get a list of my (future) events from my personal Google calendar via HTTP GET and this authentification information? I'm trying to use:

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!

2

There are 2 answers

2
SGC On BEST ANSWER

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). 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.

0
Dominic On

To anyone trying to achieve the same and who's not in the need to use API v3 at any cost:

There is still an option to get future events with a request similar to API v2. Therefore, use the private XML-code from the calendar settings and add the parameters you need. E.g.:

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. The main difference to API v2 is the "/basic?" at the end instead of the old "/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. 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 (e.g. 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.