22

How can I get a JSON with the events of a public Google Calendar? I have it's ID but no acess to it. I don't want to change its events, nor log in.

I would like get a JSON from it to sync with my PHP/MySql database.

Tried https://www.googleapis.com/calendar/v3/calendars/{calendarId}

but got login error:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Login Required",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Login Required"
 }
}
Rikard
  • 7,485
  • 11
  • 55
  • 92
  • 1
    I feel like this question was *just* asked... – admdrew Feb 03 '14 at 22:48
  • 2
    https://developers.google.com/google-apps/calendar/v3/reference/calendars/get#auth – Bugs Feb 03 '14 at 22:50
  • @admdrew, true. I asked a similar one, bad formulated. So I deleted that one, improved my text and posted again. – Rikard Feb 03 '14 at 22:51
  • Ahh ok. Good, I was feeling crazy for a second!! (not that this makes me not crazy...) – admdrew Feb 03 '14 at 22:52
  • 3
    @Bugs, thanks for the link. Had also checked it. But didn't get it to work. That links example require `OAuth 2.0` authentication. I don't need to edit the calendar, just get data from it. – Rikard Feb 03 '14 at 22:55
  • That's not the point. You aren't required to authenticate as the owner of the calendar. "Every request your application sends to the Google Calendar API must include an authorization token. The token also identifies your application to Google." – Bugs Feb 03 '14 at 22:57
  • @Bugs, is that the `ID` of the calender or I have to register my domain/php at Google and get a `key` from them? – Rikard Feb 03 '14 at 22:58
  • It has nothing to do with the calendar itself. You're required to register your app so Google can control the use of their APIs. – Bugs Feb 03 '14 at 22:59
  • @Bugs, but I can get a __[iCal](http://stackoverflow.com/questions/14086833/google-calendar-api-for-php-simple-read-only-request-to-get-calendar-events)__ from Google with a url with the ID on it, why not a JSON string? – Rikard Feb 03 '14 at 23:00
  • @admdrew, sorry if this makes you crazy :) Do you have any input about this? – Rikard Feb 03 '14 at 23:02
  • @Rikard I don't know. I'm merely interpreting the documentation. I would _guess_ that the API providers more comprehensive info, and so it's more likely to be misused. – Bugs Feb 03 '14 at 23:04

2 Answers2

55

Since November 17th 2014, v1 and v2 of the Google Calendar API have been disabled.

Google Calendar API V3 requires oauth authentication for almost all of its operations. As near as I can tell, this also requires user interaction.

However, for public calendars, it is still possible to use a single link to get JSON data (this is not currently documented by Google - I don't know if it's oversight on their part or private API that might disappear tomorrow).

  1. Register your application with the Google Developers Console
  2. Activate the Google Calendar API in the Google Developers Console.
  3. Under Credentials, create a new Public API access key (you may want to leave referrers blank for testing)
  4. The JSON url now looks like this

    https://www.googleapis.com/calendar/v3/calendars/{calendarid}/events?key={Your Public API Key}

(The curly braces {} should not present in the actual url).

The API documentation describes additional parameters you can include (except that you can also include the parameter &callback=, as with most JSON requests, to create a JSONP response for javascript).

Tirno
  • 1,568
  • 2
  • 16
  • 21
  • I don't see how to create a Public API access key. Has something changed? – royco May 05 '16 at 04:07
  • It seems there's a daily limit for this use. On my server, it returns 403 with the message "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup." But from my browser, it works fine. I can't find any documentation about the maximum requests allowed per day. – hktang Aug 30 '16 at 08:32
  • How would I get freebusy query for everyone that has shared their calendars with me. In other words, is it possible to view freebusy query for all employees at a company domain, via one calendarID (my email address), as long as everyone's calendar is shared within the same company? – Akin Hwan Dec 13 '17 at 17:58
10

Your calendar have to be shared publicly! This one works if you have shared only free/busy status:

http://www.google.com/calendar/feeds/{calendarId}@group.calendar.google.com/public/basic?orderby=starttime&sortorder=ascending&futureevents=true&alt=json

Full details - this one works only if calendar is shared fully publicly

http://www.google.com/calendar/feeds/{calendarId}@group.calendar.google.com/public/full?orderby=starttime&sortorder=ascending&futureevents=true&alt=json

Or just free-busy

http://www.google.com/calendar/feeds/{calendarId}@group.calendar.google.com/public/free-busy?orderby=starttime&sortorder=ascending&futureevents=true&alt=json

Parameters orderby, sortorder and futureevents are optional but might help you later :)

Kostas Minaidis
  • 4,681
  • 3
  • 17
  • 25
Laky
  • 373
  • 4
  • 17
  • this is not my question but your answer is very helpful to me, thanks @laky – Code cracker Feb 18 '15 at 05:33
  • 2
    Since November 2014 free-busy link does not work. To get start and end time you have to use Google Calendar API V3 described below. – Laky Feb 22 '15 at 22:12
  • Full detail URL is also not working, I assume that `{calendarId}` is needed to be replaced with email address – Shajeel Afzal Oct 26 '15 at 20:04
  • 1
    I am getting a forbidden 403 response, is this approach still valid? I find that the answer below with 43 upvotes is actually giving back a response. – Akin Hwan Dec 13 '17 at 17:57