{"id":599,"date":"2023-03-31T06:44:47","date_gmt":"2023-03-31T06:44:47","guid":{"rendered":"https:\/\/mouryasolutions.in\/blog\/?p=599"},"modified":"2023-03-31T06:46:37","modified_gmt":"2023-03-31T06:46:37","slug":"implement-google-calendar-in-codeigniter","status":"publish","type":"post","link":"https:\/\/mouryasolutions.in\/blog\/implement-google-calendar-in-codeigniter\/","title":{"rendered":"Implement Google Calendar in CodeIgniter"},"content":{"rendered":"<div class=\"post-content\">\n<p>To implement Google Calendar in CodeIgniter, you need to follow these steps:<\/p>\n\n\n\n<p>1. Create a Google API project and enable the Calendar API. Go to the Google Developers Console, create a new project, enable the Calendar API and generate the API key and OAuth2 credentials.<\/p>\n\n\n\n<p>2. Install the Google API client library for PHP using Composer. Run the following command in the root directory of your CodeIgniter project:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>composer require google\/apiclient:^2.0\n<\/code><\/pre>\n\n\n\n<p>3. Create a controller in CodeIgniter to handle the Google Calendar API requests. You can create a new controller file in the <code>application\/controllers<\/code> directory and add the following code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\ndefined('BASEPATH') OR exit('No direct script access allowed');\n\nrequire_once APPPATH.'vendor\/autoload.php';\n\nclass Calendar extends CI_Controller {\n\n    public function index()\n    {\n        \/\/ Load the Google API client library\n        $client = new Google_Client();\n        $client-&gt;setApplicationName('CodeIgniter Google Calendar');\n        $client-&gt;setDeveloperKey('YOUR_API_KEY');\n        $client-&gt;setAccessToken($this-&gt;session-&gt;userdata('access_token'));\n\n        \/\/ Get the events from the Google Calendar API\n        $service = new Google_Service_Calendar($client);\n        $events = $service-&gt;events-&gt;listEvents('primary');\n\n        \/\/ Render the view with the events data\n        $this-&gt;load-&gt;view('calendar', array('events' =&gt; $events));\n    }\n\n}\n<\/code><\/pre>\n\n\n\n<p>In this example, we create a new controller called <code>Calendar<\/code> and define an <code>index()<\/code> method to handle the Google Calendar API requests. We load the Google API client library, set the application name and API key, and get the access token from the CodeIgniter session.<\/p>\n\n\n\n<p>We then create a new <code>Google_Service_Calendar<\/code> object to interact with the Calendar API and call the <code>listEvents()<\/code> method to get the events from the primary calendar. We pass the events data to the <code>calendar<\/code> view file and render it using the CodeIgniter <code>load-&gt;view()<\/code> method.<\/p>\n\n\n\n<p>4. Create a view file in CodeIgniter to display the events data. You can create a new view file in the <code>application\/views<\/code> directory and add the following code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;h1&gt;Google Calendar Events&lt;\/h1&gt;\n\n&lt;?php foreach ($events-&gt;getItems() as $event): ?&gt;\n    &lt;h2&gt;&lt;?php echo $event-&gt;getSummary(); ?&gt;&lt;\/h2&gt;\n    &lt;p&gt;&lt;?php echo $event-&gt;getDescription(); ?&gt;&lt;\/p&gt;\n&lt;?php endforeach; ?&gt;\n<\/code><\/pre>\n\n\n\n<p>In this example, we display the events data in an HTML format using a <code>foreach<\/code> loop. We get the event summary and description using the <code>getSummary()<\/code> and <code>getDescription()<\/code> methods of the <code>Google_Service_Calendar_Event<\/code> class.<\/p>\n\n\n\n<p>5. Create a route in CodeIgniter to access the <code>Calendar<\/code> controller. You can create a new route in the <code>application\/config\/routes.php<\/code> file and add the following code:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$route&#91;'calendar'] = 'calendar';\n<\/code><\/pre>\n\n\n\n<p>This route maps the <code>\/calendar<\/code> URL to the <code>Calendar<\/code> controller&#8217;s <code>index()<\/code> method.<\/p>\n\n\n\n<p>6. Run the CodeIgniter application and access the <code>\/calendar<\/code> URL in your web browser to see the Google Calendar events data.<\/p>\n<\/div><!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>To implement Google Calendar in CodeIgniter, you need to follow<a href=\"https:\/\/mouryasolutions.in\/blog\/implement-google-calendar-in-codeigniter\/\">Read More<i class=\"fa fa-long-arrow-right\" aria-hidden=\"true\"><\/i><\/a><!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/mouryasolutions.in\/blog\/wp-json\/wp\/v2\/posts\/599"}],"collection":[{"href":"https:\/\/mouryasolutions.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mouryasolutions.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mouryasolutions.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mouryasolutions.in\/blog\/wp-json\/wp\/v2\/comments?post=599"}],"version-history":[{"count":2,"href":"https:\/\/mouryasolutions.in\/blog\/wp-json\/wp\/v2\/posts\/599\/revisions"}],"predecessor-version":[{"id":601,"href":"https:\/\/mouryasolutions.in\/blog\/wp-json\/wp\/v2\/posts\/599\/revisions\/601"}],"wp:attachment":[{"href":"https:\/\/mouryasolutions.in\/blog\/wp-json\/wp\/v2\/media?parent=599"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mouryasolutions.in\/blog\/wp-json\/wp\/v2\/categories?post=599"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mouryasolutions.in\/blog\/wp-json\/wp\/v2\/tags?post=599"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}