Google Calendar API Integration for Websites
When displaying event schedules on a website, many developers face issues with synchronization, time zones, and API quotas. Choosing the wrong authentication leads to 401 errors, and lack of caching causes quota limits to be exceeded. Our team has 10+ years of experience and over 40 successful projects integrating calendars, guaranteeing stable solutions for any load.
By integrating the Google Calendar API, you can automate bookings, sync events, and manage calendars without manual input. For example, one of our clients — a meeting room booking service — after implementing OAuth2 and push notifications, reduced schedule update time from 5 minutes to 2 seconds, cutting operational costs by over 40%.
Problems We Solve
- Authentication choice: for public data, an API Key suffices, but for private calendars, OAuth2 with a refresh token is required. Wrong choice leads to 401 errors.
- Time zones: if
timeZoneis not specified, event times will be incorrect. - Quotas and limits: the free tier of Google Calendar API allows 1,000,000 requests per day. Without caching and webhooks, you may exceed the limit.
- Real-time synchronization: if calendar changes don't reflect on the site instantly, users see stale data.
These issues are resolved with proper architecture: correct authentication, explicit timeZone setting, use of push notifications, and caching. Our solution saves up to 10 hours of manual syncing per week, reducing operational costs by 40%. Investment in integration pays back in 2–3 months through automation.
How We Do It
We use Laravel 10/11 on the backend, React or Next.js on the frontend. For API calls, we rely on the official Google API Client Library for PHP or JavaScript. Here are three common scenarios.
Public Calendar Without Authorization
To read a public calendar, an API Key is enough. Get the key from the Google Cloud Console, enable the Calendar API, and make a GET request. Always specify timeMin and orderBy to avoid pulling the full history. For caching, we use Redis with a 5-minute TTL. Example request:
$client = new Google_Client(); $client->setDeveloperKey($apiKey); $service = new Google_Service_Calendar($client); $events = $service->events->listEvents('primary', ['timeMin' => '202X-01-01T00:00:00Z', 'orderBy' => 'startTime']); OAuth2 for Private Calendars
To create, update, and delete events, OAuth2 is required. The user must grant access via the Google OAuth consent screen. After authorization, save the refresh token. In Laravel, we store tokens in the database and refresh them when they expire. Google returns an access_token valid for 1 hour and an unlimited refresh_token. Example wrapper:
$client->setAccessToken($storedToken); if ($client->isAccessTokenExpired()) { $client->fetchAccessTokenWithRefreshToken($client->getRefreshToken()); // save new access_token } For initial setup, install the library via Composer: composer require google/apiclient. Then create OAuth2 credentials in the Google Cloud Console and configure the consent screen with the scope https://www.googleapis.com/auth/calendar.events.
"Add to Google Calendar" Button
If you simply need a one-click add action without full API integration, generate a URL following the scheme https://calendar.google.com/calendar/render?action=TEMPLATE&.... The user will be redirected to Google Calendar to confirm. Ensure dates are in UTC. For multi-hour events, include both start and end dates.
Why OAuth2 Over API Key for Private Calendars?
If the calendar data is public and doesn't require write access, an API Key is sufficient. However, for creating events on behalf of users or reading/writing private calendars, OAuth2 is mandatory. OAuth2 offers 10 times more capabilities than an API Key: reading and writing private data, managing multiple calendars. Push notifications (webhooks) work only with OAuth2 and reduce update latency by 5 times compared to polling.
What If You Need to Edit Events on Behalf of a User?
Use OAuth2 with the scope https://www.googleapis.com/auth/calendar.events. After authorization, save the refresh token. On each request, check if the access token has expired and refresh it. The Google Calendar API supports full CRUD for events, as well as management of reminders and attachments.
Comparison of Integration Methods
| Method | Authentication | Data Access | Server Required |
|---|---|---|---|
| API Key | No | Read-only public | Yes |
| OAuth2 (server app) | Yes | Read/write private | Yes |
| "Add" button | No | Add only | No |
Common Errors and Solutions
| Error | Cause | Solution |
|---|---|---|
| 403 Forbidden | Wrong API Key or Calendar API not enabled | Verify key and enable API in console |
| 401 Unauthorized | Expired or invalid access_token | Use refresh_token to renew |
| Wrong time | No timeZone specified | Always pass timeZone explicitly, e.g., Europe/Moscow |
| Quota exceeded | Too many requests | Cache requests, use pagination and webhooks |
Example OAuth2 request to create an event
$event = new Google_Service_Calendar_Event([ 'summary' => 'Meeting', 'start' => ['dateTime' => '202X-06-01T10:00:00', 'timeZone' => 'Europe/Moscow'], 'end' => ['dateTime' => '202X-06-01T11:00:00', 'timeZone' => 'Europe/Moscow'], ]); $createdEvent = $service->events->insert('primary', $event); Process Overview
- Analysis: determine use cases (public calendar, booking, sync).
- Design: choose authentication type, design token database.
- Implementation: write code in Laravel/React, configure Google Cloud Console.
- Testing: verify authorization, error handling, quotas.
- Deployment: set up environment variables (
GOOGLE_API_KEY, etc.), enable HTTPS.
What’s Included in the Integration
- Setup of project in Google Cloud Console (creation of OAuth2 credentials, API key).
- Implementation of frontend widget (React/Vue) to display events.
- Backend endpoints for CRUD operations with error handling.
- Refresh token mechanism with database storage.
- Operational documentation (how to refresh tokens, manage quotas).
- Post-launch support (1 month).
Timelines
- Public events widget: from 1 day.
- OAuth2 with private calendar read/write: from 3 days.
- Full booking system with real-time sync: from 5 days.
Cost is determined individually — contact us for a free assessment of your project. Request a development quote and get a ready-to-use solution.
Reference: Google Calendar API Overview







