{"id":1523,"date":"2024-09-06T15:48:05","date_gmt":"2024-09-06T15:48:05","guid":{"rendered":"https:\/\/debugspot.com\/?p=1523"},"modified":"2024-09-06T16:54:57","modified_gmt":"2024-09-06T16:54:57","slug":"integrate-google-calendar-with-laravel","status":"publish","type":"post","link":"https:\/\/debugspot.com\/blogs\/integrate-google-calendar-with-laravel\/","title":{"rendered":"Sync Google Calendar with Your Laravel Site: A Comprehensive Guide"},"content":{"rendered":"<p>How to integrate google calendar api in laravel application using can streamline event management.<\/p>\n<p>Syncing Google Calendar with your Laravel application is easier than you think! By following these simple steps, you can set up the Google Calendar API and manage calendar events programmatically using Laravel. Here\u2019s a complete guide to get you started:<\/p>\n<p>Integrating Google Calendar with Laravel can boost your productivity by enabling seamless event management within your application. In this tutorial, you&#8217;ll learn how to set up the Google Calendar API, create OAuth 2.0 credentials, and sync Google Calendar with your Laravel app. Follow these simple steps to streamline your calendar management using Laravel.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/debugspot.com\/blogs\/integrate-google-calendar-with-laravel\/#Step_1_Set_Up_Google_API_Credentials\" >Step 1: Set Up Google API Credentials<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/debugspot.com\/blogs\/integrate-google-calendar-with-laravel\/#11_Create_a_New_Project_in_Google_Developers_Console\" >1.1 Create a New Project in Google Developers Console<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/debugspot.com\/blogs\/integrate-google-calendar-with-laravel\/#12_Enable_the_Google_Calendar_API\" >1.2 Enable the Google Calendar API<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/debugspot.com\/blogs\/integrate-google-calendar-with-laravel\/#13_Create_OAuth_20_Credentials\" >1.3 Create OAuth 2.0 Credentials<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/debugspot.com\/blogs\/integrate-google-calendar-with-laravel\/#Step_2_Use_OAuth_20_Playground\" >Step 2: Use OAuth 2.0 Playground<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/debugspot.com\/blogs\/integrate-google-calendar-with-laravel\/#21_Access_OAuth_20_Playground\" >2.1 Access OAuth 2.0 Playground<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/debugspot.com\/blogs\/integrate-google-calendar-with-laravel\/#22_Authorize_APIs\" >2.2 Authorize APIs<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/debugspot.com\/blogs\/integrate-google-calendar-with-laravel\/#Step_3_Exchange_Authorization_Code_for_Tokens\" >Step 3: Exchange Authorization Code for Tokens<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/debugspot.com\/blogs\/integrate-google-calendar-with-laravel\/#31_Obtain_Authorization_Code\" >3.1 Obtain Authorization Code<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/debugspot.com\/blogs\/integrate-google-calendar-with-laravel\/#32_Update_credentialsjson_File\" >3.2 Update credentials.json File<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/debugspot.com\/blogs\/integrate-google-calendar-with-laravel\/#Step_4_Implement_Google_Calendar_Integration_in_Laravel\" >Step 4: Implement Google Calendar Integration in Laravel<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/debugspot.com\/blogs\/integrate-google-calendar-with-laravel\/#41_Install_Google_Client_Library\" >4.1 Install Google Client Library<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/debugspot.com\/blogs\/integrate-google-calendar-with-laravel\/#42_Use_Google_Calendar_API_in_Laravel\" >4.2 Use Google Calendar API in Laravel<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/debugspot.com\/blogs\/integrate-google-calendar-with-laravel\/#Summary\" >Summary<\/a><ul class='ez-toc-list-level-5' ><li class='ez-toc-heading-level-5'><ul class='ez-toc-list-level-5' ><li class='ez-toc-heading-level-5'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/debugspot.com\/blogs\/integrate-google-calendar-with-laravel\/#You_may_also_find_interesting\" >You may also find interesting:<\/a><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_1_Set_Up_Google_API_Credentials\"><\/span>Step 1: Set Up Google API Credentials<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"11_Create_a_New_Project_in_Google_Developers_Console\"><\/span><strong>1.1 Create a New Project in Google Developers Console<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<ol>\n        <img decoding=\"async\" src=\"https:\/\/debugspot.com\/blogs\/wp-content\/uploads\/2024\/09\/Screenshot.png\" alt=\"Google Calendar API in laravel\" \/> <\/p>\n<li>Visit the<a href=\"https:\/\/console.cloud.google.com\/\" target=\"_blank\" rel=\"noopener\"> Google Developers Console<\/a>.<\/li>\n<li>Click &#8220;Select a project&#8221; at the top, then &#8220;New Project.<\/li>\n<li>Enter a project name and click &#8220;Create.<\/li>\n<\/ol>\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"12_Enable_the_Google_Calendar_API\"><\/span><strong>1.2 Enable the Google Calendar API<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<ol>\n        <img decoding=\"async\" src=\"https:\/\/debugspot.com\/blogs\/wp-content\/uploads\/2024\/09\/go-to-library.png\" alt=\"Navigate API &#038; Services\" \/><\/p>\n<li>Navigate to API &#038; Services > Library.<\/li>\n<li>Search for &#8220;Google Calendar API.<\/li>\n<p>         <img decoding=\"async\" src=\"https:\/\/debugspot.com\/blogs\/wp-content\/uploads\/2024\/09\/enabled-api.png\" alt=\"Google Calendar API in laravel\" \/><\/p>\n<li>Click &#8220;Enable&#8221; to activate the Google Calendar API for your project.<\/li>\n<\/ol>\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"13_Create_OAuth_20_Credentials\"><\/span><strong>1.3 Create OAuth 2.0 Credentials<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<ol>\n<li>Go to &#8220;API &#038; Services&#8221; > Credentials.<\/li>\n<li>Click &#8220;Create Credentials&#8221; and select &#8220;OAuth 2.0 Client IDs.<\/li>\n<li>Configure the consent screen and choose &#8220;Web application.<\/li>\n<li>Download the credentials.json file and place it in the storage\/app directory of your Laravel project.<\/li>\n<\/ol>\n<pre class=\"highlight-height line-numbers language-javascript\"><code class=\"language-javascript\">\r\n{\r\n  \"client_id\": \"YOUR_CLIENT_ID.apps.googleusercontent.com\",\r\n  \"client_secret\": \"YOUR_CLIENT_SECRET\"\r\n}\r\n<\/code><\/pre>\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_2_Use_OAuth_20_Playground\"><\/span>Step 2: Use OAuth 2.0 Playground<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"21_Access_OAuth_20_Playground\"><\/span><strong>2.1 Access OAuth 2.0 Playground<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<ol>\n<li><a href=\"https:\/\/console.cloud.google.com\/project\" target=\"_blank\" rel=\"noopener\">Go to OAuth 2.0 Playground<\/a>.<\/li>\n<li>In settings, check &#8220;Use your own OAuth credentials.<\/li>\n<li>Enter your Client ID and Client Secret from credentials.json.<\/li>\n<\/ol>\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"22_Authorize_APIs\"><\/span><strong>2.2 Authorize APIs<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<ol>\n<li>In Step 1, find &#8220;Google Calendar API v3&#8221; and click &#8220;Authorize APIs.<\/li>\n<li>Log in and authorize access to your Google Calendar.<\/li>\n<\/ol>\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_3_Exchange_Authorization_Code_for_Tokens\"><\/span>Step 3: Exchange Authorization Code for Tokens<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"31_Obtain_Authorization_Code\"><\/span><strong>3.1 Obtain Authorization Code<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<ol>\n<li>After authorizing, click the &#8220;Exchange authorization code for tokens&#8221; button.<\/li>\n<li>You\u2019ll receive an access token and refresh token.<\/li>\n<\/ol>\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"32_Update_credentialsjson_File\"><\/span><strong>3.2 Update credentials.json File<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Update your credentials.json file to include the tokens:<\/p>\n<pre class=\"highlight-height line-numbers language-javascript\"><code class=\"language-javascript\">\r\n    {\r\n        \"client_id\": \"YOUR_CLIENT_ID.apps.googleusercontent.com\",\r\n        \"client_secret\": \"YOUR_CLIENT_SECRET\",\r\n        \"access_token\": \"YOUR_ACCESS_TOKEN\",\r\n        \"scope\": \"https:\/\/www.googleapis.com\/auth\/calendar.events\",\r\n        \"token_type\": \"Bearer\",\r\n        \"expires_in\": 3599,\r\n        \"refresh_token\": \"YOUR_REFRESH_TOKEN\"\r\n        }      \r\n<\/code><\/pre>\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Step_4_Implement_Google_Calendar_Integration_in_Laravel\"><\/span>Step 4: Implement Google Calendar Integration in Laravel<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"41_Install_Google_Client_Library\"><\/span><strong>4.1 Install Google Client Library<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>To interact with the Google Calendar API in Laravel, install the Google API client library:<\/p>\n<pre class=\"highlight-height line-numbers language-javascript\"><code class=\"language-javascript\"> composer require google\/apiclient  <\/code><\/pre>\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"42_Use_Google_Calendar_API_in_Laravel\"><\/span><strong>4.2 Use Google Calendar API in Laravel<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>Create a service to handle Google Calendar interactions using the credentials in your credentials.json file.<\/p>\n<p>Example to list events from Google Calendar in a Laravel controller:<\/p>\n<pre class=\"highlight-height line-numbers language-javascript\"><code class=\"language-javascript\">\r\n    use Google_Client;\r\n    use Google_Service_Calendar;\r\n    \r\n    class GoogleCalendarController extends Controller\r\n    {\r\n        public function listEvents()\r\n        {\r\n            $client = new Google_Client();\r\n            $client->setAuthConfig(storage_path('app\/credentials.json'));\r\n            $client->addScope(Google_Service_Calendar::CALENDAR_READONLY);\r\n    \r\n            $service = new Google_Service_Calendar($client);\r\n            $calendarId = 'primary';\r\n            $events = $service->events->listEvents($calendarId);\r\n    \r\n            foreach ($events->getItems() as $event) {\r\n                echo $event->getSummary() . \"<br>\";\r\n            }\r\n        }\r\n    }        \r\n<\/code><\/pre>\n<p>Now, you can sync Google Calendar with Laravel and manage your calendar events effortlessly from your application.<\/p>\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Summary\"><\/span>Summary<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>This blog provides a step-by-step guide to integrating Google Calendar with a Laravel site using the Google Calendar API. It covers setting up Google API credentials, configuring OAuth 2.0, and managing calendar events programmatically within Laravel. The tutorial includes creating a Google project, enabling the API, obtaining OAuth 2.0 tokens, and using the Google API client library in Laravel to list and manage calendar events. With this guide, you&#8217;ll streamline calendar management and enhance your Laravel application&#8217;s functionality.<\/p>\n<h5><span class=\"ez-toc-section\" id=\"You_may_also_find_interesting\"><\/span>You may also find interesting:<span class=\"ez-toc-section-end\"><\/span><\/h5>\n<p><a title=\"Custom Middleware in Laravel 11\" href=\"https:\/\/debugspot.com\/blogs\/create-custom-middleware-in-laravel-11\/\" target=\"_blank\" rel=\"noopener\">Custom Middleware in Laravel 11<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to integrate google calendar api in laravel application using can streamline event management. Syncing Google Calendar with your Laravel application is easier than you think! By following these simple steps, you can set up the Google Calendar API and manage calendar events programmatically using Laravel. Here\u2019s a complete guide to get you started: Integrating Google Calendar with Laravel can boost your productivity by enabling seamless event management within your application. In this tutorial, you&#8217;ll learn how to set up the Google Calendar API, create OAuth 2.0 credentials, and sync Google Calendar with your Laravel app. Follow these simple steps to streamline your calendar management using Laravel. Step 1: Set Up Google API Credentials 1.1 Create a New Project in Google Developers Console Visit the Google Developers Console. Click &#8220;Select a project&#8221; at the top, then &#8220;New Project. Enter a project name and click &#8220;Create. 1.2 Enable the Google Calendar API Navigate to API &#038; Services > Library. Search for &#8220;Google Calendar API. Click &#8220;Enable&#8221; to activate the Google Calendar API for your project. 1.3 Create OAuth 2.0 Credentials Go to &#8220;API &#038; Services&#8221; > Credentials. Click &#8220;Create Credentials&#8221; and select &#8220;OAuth 2.0 Client IDs. Configure the consent screen and &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"rank_math_lock_modified_date":false,"footnotes":""},"categories":[3],"tags":[23,40,46,45,39],"class_list":["post-1523","post","type-post","status-publish","format-standard","hentry","category-laravel","tag-google-fcm","tag-integrate-google-calendar-with-laravel","tag-laravel","tag-laravel-google-calendar-api-example","tag-laravel-google-calendar-sync"],"acf":[],"_links":{"self":[{"href":"https:\/\/debugspot.com\/blogs\/wp-json\/wp\/v2\/posts\/1523"}],"collection":[{"href":"https:\/\/debugspot.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/debugspot.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/debugspot.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/debugspot.com\/blogs\/wp-json\/wp\/v2\/comments?post=1523"}],"version-history":[{"count":16,"href":"https:\/\/debugspot.com\/blogs\/wp-json\/wp\/v2\/posts\/1523\/revisions"}],"predecessor-version":[{"id":1545,"href":"https:\/\/debugspot.com\/blogs\/wp-json\/wp\/v2\/posts\/1523\/revisions\/1545"}],"wp:attachment":[{"href":"https:\/\/debugspot.com\/blogs\/wp-json\/wp\/v2\/media?parent=1523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/debugspot.com\/blogs\/wp-json\/wp\/v2\/categories?post=1523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/debugspot.com\/blogs\/wp-json\/wp\/v2\/tags?post=1523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}