Add Google Calendar to your app
Most apps do not need the Google Calendar API. Start with a link or a feed, and reach for OAuth only when you must read someone’s busy times.

Key takeaways
- An Add to Google Calendar link or an .ics file needs no API, no key and no Google review. Start there.
- A subscribable calendar feed keeps events updated, but Google refreshes subscribed feeds on its own schedule, often hours apart.
- Reading busy times or writing into a user’s calendar needs OAuth. Store refresh tokens server-side, request the narrowest scope and plan for Google’s app verification.
Adding Google Calendar to an app can mean three different things, and the simplest one is usually enough. If you want people to save an event, give them an Add to Google Calendar link or an `.ics` file: no API, no account, no keys. If you want a calendar that stays updated, publish an ICS feed they subscribe to. Only if your app must read someone's busy times or write events into their calendar do you need the Google Calendar API with OAuth, which brings a Google Cloud project, a consent screen, tokens in your backend and possibly a verification review.
Level 1: add-to-calendar links and .ics files
A booking confirmation, an event page or a webinar signup only needs to hand the event over once. Google accepts a template URL that opens a prefilled event: `https://calendar.google.com/calendar/render?action=TEMPLATE&text=Pottery+class&dates=20261205T170000Z/20261205T190000Z&details=Bring+an+apron&location=12+Mill+Lane`. Times are UTC with a trailing `Z`, which avoids every time zone bug at once.
Next to it, offer an `.ics` download (the iCalendar format) for Apple Calendar and Outlook users. A small edge function can generate one per booking with a stable `UID` such as `booking-1042@yourdomain.com`; if you later send an updated file with the same UID and a higher `SEQUENCE`, calendar apps treat it as a change rather than a duplicate. Attach the same file to the confirmation email and most mail apps show an 'Add to calendar' button.
Level 2: a subscribable calendar feed
A sports team app, a class timetable or a shift rota changes over time. Instead of one-off files, give each user a private feed URL like `/functions/v1/calendar-feed?token=8f3c...` that returns all their upcoming events as one iCalendar document. In Google Calendar they choose 'From URL' under other calendars and paste it. Every change you make shows up without them doing anything again.
- The token is the password. Generate a long random token per user, store only its hash, and add a 'Reset feed link' button. The function must be public, since Google fetches it without a session, so the token is the only lock.
- Refresh is not instant. Google re-fetches subscribed calendars on its own schedule, which can be many hours apart, and you cannot force it. Tell users so, and keep urgent changes (a cancelled game) on email or push as well.
- Keep it small. Include, say, the past 30 days and the next 12 months, not every event since launch.
Level 3: the Calendar API with OAuth
The classic case: a tutoring marketplace where each tutor connects their Google Calendar. The app reads their busy times so students cannot book a slot that clashes with a dentist appointment, and writes each confirmed lesson into the tutor's calendar. Now you are acting on a user's data, and that means OAuth.
What you need
- 01A Google Cloud project with the Google Calendar API enabled and an OAuth consent screen (app name, support email, privacy policy URL, authorized domains).
- 02An OAuth client of type web application, with your callback function's URL as an authorized redirect URI. Store the client ID and secret in Backend → Secrets as `GOOGLE_CALENDAR_CLIENT_ID` and `GOOGLE_CALENDAR_CLIENT_SECRET`.
- 03The narrowest scopes. For busy times only, request free/busy or read-only access; add event write access only if you insert events. Calendar scopes are classed as sensitive, so publishing your consent screen to the public can require Google's verification review. Check Google's current requirements before you launch.
- 04A `calendar_connections` table with `user_id`, `google_email`, `refresh_token` (encrypted), `scopes`, `connected_at` and `last_error`, readable only by your backend.
The data flow
- 01The tutor clicks Connect Google Calendar. A `calendar-connect` function builds Google's authorization URL with your scopes, offline access (so you receive a refresh token) and a random `state` value tied to the tutor's session.
- 02Google redirects to `calendar-callback` with a code. The function checks `state`, exchanges the code for tokens with the client secret, and saves the refresh token server-side.
- 03When a student opens the booking page, a `tutor-availability` function uses the refresh token to get a short-lived access token, queries free/busy for the next 14 days, subtracts busy blocks from the tutor's working hours and returns open slots. Cache the result for a few minutes per tutor.
- 04When a lesson is confirmed, the function re-checks free/busy for that slot (someone may have booked it in Google in the meantime), inserts the event and stores the Google event id on the booking so a cancellation can delete it.
Paste-ready brief
Let tutors connect Google Calendar in my booking app. The OAuth client id and secret are in Secrets as GOOGLE_CALENDAR_CLIENT_ID and GOOGLE_CALENDAR_CLIENT_SECRET. Add a Connect Google Calendar button on the tutor settings page that runs an OAuth flow with offline access and a state check, requesting free/busy read and event write scopes only. Store the refresh token encrypted in a calendar_connections table no client can read. Build tutor-availability to return open 60-minute slots for the next 14 days from the tutor's working hours minus Google busy times, cached for 5 minutes. On booking, re-check the slot, insert the event in the tutor's calendar with the student's first name, and store the event id; delete it on cancellation. Give students an Add to Google Calendar link and an .ics file in their confirmation. Show a Reconnect banner if the token stops working.
Pitfalls
- Refresh tokens in the browser. A refresh token grants ongoing access to someone's calendar. It lives only in your database, read only by edge functions; the browser sees open slots, never tokens.
- Testing-mode surprises. While a Google OAuth app is in testing status, only listed test users can connect, and refresh tokens for apps in that status expire after about a week. Everything works for you, then breaks for everyone else, or for you a week later.
- Revoked access. Users can remove your app from their Google account at any time. Catch `invalid_grant` errors, mark the connection broken and ask them to reconnect.
- Time zones. Store everything in UTC, keep each tutor's time zone, and convert at the edges. Daylight saving changes are where slot math usually breaks.
- Rate limits and quotas. The Calendar API has per-project and per-user quotas. Cache availability and avoid querying every tutor on every page view of a busy marketplace.
- Over-asking. Requesting full calendar access when you only need free/busy scares people off at the consent screen and makes verification harder.
The booking system guide covers slots, buffers, cancellations and reminders around this integration.
Frequently asked questions
Do I need the Google Calendar API to add events to a calendar?
No. An Add to Google Calendar template link or an .ics file lets users save an event with no API key, no OAuth and no Google review. The API is for reading busy times or writing into calendars on a user behalf.
Why do changes to my calendar feed take hours to show in Google Calendar?
Google refreshes subscribed external calendars on its own schedule, often hours apart, and apps cannot force a refresh. Send urgent changes by email or push as well.
Where should I store Google OAuth tokens?
In a backend table only your edge functions can read, with the refresh token encrypted. The client ID and secret go in Backend → Secrets. Never send tokens to the browser.
Does Sign in with Google give my app calendar access?
Not by itself. Sign-in and calendar access are separate grants. Ask for calendar scopes in a separate Connect step only when the user needs that feature.

