Rikard
Rikard

Reputation: 7805

Get JSON from a public Google Calendar

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

Upvotes: 23

Views: 29690

Answers (2)

Laky
Laky

Reputation: 193

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

Upvotes: 10

Tirno
Tirno

Reputation: 1578

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

Upvotes: 55

Related Questions