Get JSON from a public Google Calendar

24,555

Solution 1

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

Solution 2

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

Share:
24,555

Related videos on Youtube

Rikard
Author by

Rikard

Updated on September 22, 2020

Comments

  • Rikard
    Rikard over 3 years

    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"
     }
    }
    
    • admdrew
      admdrew over 10 years
      I feel like this question was just asked...
    • Bugs
      Bugs over 10 years
    • Rikard
      Rikard over 10 years
      @admdrew, true. I asked a similar one, bad formulated. So I deleted that one, improved my text and posted again.
    • admdrew
      admdrew over 10 years
      Ahh ok. Good, I was feeling crazy for a second!! (not that this makes me not crazy...)
    • Rikard
      Rikard over 10 years
      @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.
    • Bugs
      Bugs over 10 years
      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."
    • Rikard
      Rikard over 10 years
      @Bugs, is that the ID of the calender or I have to register my domain/php at Google and get a key from them?
    • Bugs
      Bugs over 10 years
      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.
    • Rikard
      Rikard over 10 years
      @Bugs, but I can get a iCal from Google with a url with the ID on it, why not a JSON string?
    • Rikard
      Rikard over 10 years
      @admdrew, sorry if this makes you crazy :) Do you have any input about this?
    • Bugs
      Bugs over 10 years
      @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.
  • Code cracker
    Code cracker about 9 years
    this is not my question but your answer is very helpful to me, thanks @laky
  • Laky
    Laky about 9 years
    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.
  • Shajeel Afzal
    Shajeel Afzal over 8 years
    Full detail URL is also not working, I assume that {calendarId} is needed to be replaced with email address
  • royco
    royco about 8 years
    I don't see how to create a Public API access key. Has something changed?
  • hktang
    hktang over 7 years
    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.
  • Akin Hwan
    Akin Hwan over 6 years
    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
    Akin Hwan over 6 years
    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?