tech@designanddevelopment.tech +91 9511638160
Build Your Website in 1 Day 100% Money-Back Guarantee
Claim Offer
Free Tools Get A Quote
API Integration Tutorials

Connecting Your Laravel App to the Google Calendar API: A Step‑by‑Step Guide for Seamless Scheduling

Learn how to integrate Google Calendar API with a Laravel application to create, read, update, and delete events. This tutorial covers OAuth 2.0 authentication, setting up Google …

DD D&D TechnologyTech Insights Jun 08, 2026 6 min read
Connecting Your Laravel App to the Google Calendar API: A Step‑by‑Step Guide for Seamless Scheduling
Share:

Why Integrate Google Calendar API with Laravel?

Scheduling is a critical part of modern business operations. Whether you run a SaaS platform, an eCommerce store, or a service-based business, automating appointment booking, event reminders, and team calendars saves time and reduces manual errors. By connecting your Laravel application to the Google Calendar API, you can programmatically create, read, update, and delete calendar events — giving your users and customers a seamless scheduling experience.

At D&D Technology, we help startups, small businesses, and enterprises build scalable digital solutions with powerful API integrations. This step-by-step guide walks you through the entire process of integrating Google Calendar API into your Laravel app.

What You'll Need Before You Start

Before diving into the code, make sure you have the following prerequisites in place:

  • A working Laravel application (Laravel 9 or later recommended)
  • A Google account with access to the Google Cloud Console
  • Composer installed on your development machine
  • Basic understanding of Laravel service providers and middleware
  • PHP 8.1 or higher

Step 1: Set Up a Google Cloud Project and Enable the Calendar API

The first step is to create a project in the Google Cloud Console and enable the Google Calendar API:

  1. Go to the Google Cloud Console and create a new project.
  2. Navigate to APIs & Services → Library and search for "Google Calendar API."
  3. Click on the Google Calendar API result and click Enable.
  4. Go to APIs & Services → Credentials and click Create Credentials → OAuth Client ID.
  5. Configure the consent screen if prompted. Choose "External" for the user type and fill in the required fields.
  6. For the application type, select Web Application.
  7. Add your callback URL (e.g., https://yourdomain.com/auth/google/callback) under "Authorized redirect URIs."
  8. Save the Client ID and Client Secret — you'll need them in the next step.

Step 2: Install Laravel Socialite and Google API Client

Laravel Socialite simplifies OAuth authentication, and the Google API Client library handles calendar operations. Install both via Composer:

composer require laravel/socialite
google/apiclient:^2.0

Step 3: Configure Environment Variables

Add your Google credentials to the .env file:

GOOGLE_CLIENT_ID=your-client-id
GOOGLE_CLIENT_SECRET=your-client-secret
GOOGLE_REDIRECT_URI=https://yourdomain.com/auth/google/callback

Then, update config/services.php to include the Google configuration:

'google' => [
    'client_id' => env('GOOGLE_CLIENT_ID'),
    'client_secret' => env('GOOGLE_CLIENT_SECRET'),
    'redirect' => env('GOOGLE_REDIRECT_URI'),
],

Step 4: Create the Authentication Routes and Controller

Create routes in routes/web.php to handle the OAuth flow:

Route::get('/auth/google', [GoogleCalendarController::class, 'redirectToGoogle']);
Route::get('/auth/google/callback', [GoogleCalendarController::class, 'handleGoogleCallback']);

In your controller, use Socialite to handle the redirect and callback:

use Laravel\Socialite\Facades\Socialite;
use Illuminate\Support\Facades\Auth;

public function redirectToGoogle()
{
    return Socialite::driver('google')
        ->scopes(['https://www.googleapis.com/auth/calendar'])
        ->redirect();
}

public function handleGoogleCallback()
{
    $googleUser = Socialite::driver('google')->user();

    // Store the token in the database
    $user = Auth::user();
    $user->google_token = $googleUser->token;
    $user->google_refresh_token = $googleUser->refreshToken;
    $user->save();

    return redirect('/dashboard')->with('success', 'Google Calendar connected successfully!');
}

Step 5: Build a Reusable Google Calendar Service Class

To keep your code clean and maintainable, create a dedicated service class for calendar operations:

namespace App\Services;

use Google\Client;
use Google\Service\Calendar;
use Google\Service\Calendar\Event;

class GoogleCalendarService
{
    protected $client;
    protected $service;

    public function __construct($user)
    {
        $this->client = new Client();
        $this->client->setClientId(config('services.google.client_id'));
        $this->client->setClientSecret(config('services.google.client_secret'));
        $this->client->setAccessToken($user->google_token);

        // Refresh token if expired
        if ($this->client->isAccessTokenExpired() && $user->google_refresh_token) {
            $this->client->fetchAccessTokenWithRefreshToken($user->google_refresh_token);
        }

        $this->service = new Calendar($this->client);
    }

    public function createEvent($calendarId, $eventData)
    {
        $event = new Event([
            'summary' => $eventData['summary'],
            'description' => $eventData['description'] ?? '',
            'start' => ['dateTime' => $eventData['start'], 'timeZone' => 'Asia/Kolkata'],
            'end' => ['dateTime' => $eventData['end'], 'timeZone' => 'Asia/Kolkata'],
        ]);

        return $this->service->events->insert($calendarId, $event);
    }

    public function getEvents($calendarId, $timeMin, $timeMax)
    {
        $optParams = [
            'timeMin' => $timeMin,
            'timeMax' => $timeMax,
            'singleEvents' => true,
            'orderBy' => 'startTime',
        ];

        return $this->service->events->listEvents($calendarId, $optParams);
    }

    public function updateEvent($calendarId, $eventId, $eventData)
    {
        $event = $this->service->events->get($calendarId, $eventId);
        $event->setSummary($eventData['summary']);
        $event->setDescription($eventData['description'] ?? '');

        return $this->service->events->update($calendarId, $eventId, $event);
    }

    public function deleteEvent($calendarId, $eventId)
    {
        return $this->service->events->delete($calendarId, $eventId);
    }
}

Step 6: Use the Service in Your Controller

With the service class in place, you can easily perform CRUD operations on calendar events:

use App\Services\GoogleCalendarService;

public function storeEvent(Request $request)
{
    $user = Auth::user();
    $calendarService = new GoogleCalendarService($user);

    $event = $calendarService->createEvent('primary', [
        'summary' => $request->input('title'),
        'description' => $request->input('description'),
        'start' => $request->input('start_time'),
        'end' => $request->input('end_time'),
    ]);

    return redirect()->back()->with('success', 'Event created: ' . $event->htmlLink);
}

Step 7: Handle Token Refresh and Error Management

Access tokens expire after a short period. Always handle token refresh gracefully and implement proper error handling:

  • Store both the access_token and refresh_token in your database.
  • Check for token expiration before every API call.
  • Use try-catch blocks around API operations to handle exceptions.
  • Log errors for debugging and notify users when re-authentication is needed.

Best Practices for Google Calendar API Integration

To ensure a reliable and secure integration, follow these best practices:

  • Use service accounts for server-to-server communication where user authentication is not required.
  • Implement rate limiting to stay within Google API quotas.
  • Cache calendar data where appropriate to reduce API calls.
  • Always validate and sanitize user input before passing it to the API.
  • Use webhooks (push notifications) to get real-time updates instead of polling the API repeatedly.

How D&D Technology Can Help

Building robust API integrations requires experience with authentication flows, error handling, and scalable architecture. At D&D Technology, a leading web development company in Jaipur, we specialize in Laravel development, API integration services, SaaS development, and AI automation for businesses worldwide.

Whether you're a startup building your first SaaS product or an enterprise looking to automate scheduling across teams, our team can design and develop a tailored solution that fits your business needs. We provide end-to-end technology solutions — from planning and UI/UX design to development, testing, deployment, and long-term support.

Contact us for a free consultation and let's discuss how we can help you integrate Google Calendar or any other API into your Laravel application.

Conclusion

Integrating Google Calendar API with your Laravel application opens up powerful automation possibilities for scheduling, event management, and customer engagement. By following this guide, you can set up OAuth 2.0 authentication, manage tokens with Laravel Socialite, and build a reusable service class for all your calendar operations.

The key to a successful integration is clean code, proper error handling, and a scalable architecture. If you need professional assistance, D&D Technology is here to help you build secure, scalable, and growth-focused digital solutions — Design. Develop. Deliver.

Was this article helpful? 4.8 (128 votes)
DD
D&D Technology
We help businesses grow with modern websites, web apps, and digital
solutions powered by the latest technologies.
View All Posts

Join the Conversation

0 Comments
AI

Ready to Add AI in Your Ecommerce Platform?

Launch automation, chatbot, recommendation engine and smart dashboards.

Transparent Process
Clear steps, no hidden charges
Fast Project Kickoff
Start your project immediately
Dedicated Expert Team
Experienced, reliable, innovative
24/7 Support
We're here whenever you need us

Build Your Website in 1 Day

From design to launch — fast turnaround without compromising quality.

Get Started

Launch Your SaaS in 1 Day

Production-ready SaaS platform with auth, payments, and admin — done in 24 hours.

See SaaS Products

100% Money-Back Guarantee

Not satisfied? Get a full refund — no questions asked. Your trust is our priority.

Talk to Us
Flexible Start Plans

Start Your Project with a Small First Step

Pay the essential setup cost or your first EMI, and our team starts building right away.

WEBSITE LAUNCH

Pay Your Domain +
1 Month EMI

Secure your domain, pay your first EMI, and we begin your website design and development immediately.

Domain Setup 1st EMI Website Work Starts
Start Website Project
Perfect for business websites, portfolios & eCommerce
APP LAUNCH

Pay Play Store Fee +
1 Month EMI

Cover your Play Store setup and first EMI, and we start your Android/iOS app design and development.

Play Store Setup 1st EMI App Work Starts
Start App Project
Ideal for startup apps, booking apps & business apps
SOFTWARE LAUNCH

Pay 1 Month EMI &
Start Your Software

Begin your custom software journey with the first EMI and our team starts planning, UI/UX, and development.

1st EMI Project Kickoff Software Development
Start Software Project
Best for ERP, CRM, HRMS, SaaS & custom systems
Transparent EMI ProcessClear pricing, no hidden charges.
Fast Project KickoffStart within 24–48 hours.
Dedicated Expert TeamExperienced, reliable & responsive.