Reputation: 51
I'm trying to embed the Google Calendar view but for each user there is a different calendar therefore I was wondering if there is a way to get the calendar src directly from the API? I looked around in their documentation yet I wasn't able to find anything useful.
Upvotes: 3
Views: 928
Reputation: 61914
As long as you know the ID of the calendar, then the embed link is standard every time, something like this:
<iframe src="https://calendar.google.com/calendar/embed?src=[TheCalendarID]&ctz=Europe%2FLondon" style="border: 0" width="800" height="600" frameborder="0" scrolling="no"></iframe>
...where [The CalendarID]
is the GUID of the calendar. If you're interacting with the calendar through the API then chances are you already know this ID, otherwise you wouldn't be able to make API calls which deal with this calendar specifically. The API also provides a way to get a list of all the calendars in the user's account, so you can discover them that way too. For a user's "primary" calendar (i.e. the main one), the ID of their Google account (suitably URL-encoded) can also be used as the src
.
Here's an example of embedding a public "Holidays in the UK" calendar (shared by Google themselves) in a page in this way: https://jsfiddle.net/7s63dqk5/
P.S. You might need to use the API to get the timezone setting, if that's useful to you - see here for the API call to use, or you can just remove that parameter from the src
URL in the iFrame.
N.B. If the user has not made the calendar public, then the link will not work unless the browser session is logged in using the relevant Google account. The exception might be if they have shared the calendar with another Google account, and the browser is logged into that second account instead.
Upvotes: 4