Manage google calendar events.
- Read Events
 - Update Event
 - Delete Event
 - Create Event
 
- The first step is to obtain credentials to access Google's API. I'm going to assume you already have a Google account and are logged in. Select a project in the Google API console clicking "Select a project."
 
- Click on ENABLE APIS AND SERVICES
 
- Search for calendar
 
- Chose GOOGLE calendar API
 
- Enable Api
 
- Go back to dashboard and Click on Credentials
 
- Click On Create Crendentials and chose Service Account
 
- Fill up details
 
- Finish the setup by clicking on done
 
- Click on newly Create Service Account Note the email for nex step. You have to use this email to manage calendar
 
- Click on keys
 
- Click on Add new key
 
- Chose Json and Download the key
 
- Go to Google calendar and Create a new calendar or chose a calendar.
 
- Scroll down to Share with specific people
 
- Click on add people and Add the Service account email ID which you copied or get it from the JSON File
 
- Finally Note Down calendar ID
 
- Install Google App Client via composer:
composer require google/apiclient:^2.11 - Download this library by clicking here
 - Extract the library to your project folder.
 - Open Application/config/gcalendar.php file
 - Add calendar ID and Json File Location (which you downloaded when you were generating Service account in the first step) . (I recomend you to put the JSON file in calendarData Folder)
 
$config['calendarId'] = "CALENDAR_ID";
$config['calendar_json_path'] = "SERVICE_ACCOUNT_JSON_FILE";//eg calendarData/calendarAPI.jsonFirst Call The Library in Controller
$this->load->library("googlecalendar");
- Load Events
 
$this->googlecalendar->getAll();- Load Specific Event
 
$this->googlecalendar->find("event_id");- Query Event
 
$this->googlecalendar->where("key1","value1")->where("key2","value2")->get();- Update Event
 
$this->googlecalendar->find("event_id");
$event->setSummary('Appointment at Somewhere');
$event->setLocation('Bangladesh');
$this->googlecalendar->update($event);- Delete Event
 
$this->googlecalendar->delete("event_id");- Create Event
 
$data = array(
            'summary' => 'Google I/O 2015',
            'location' => '800 Howard St., San Francisco, CA 94103',
            'description' => 'A chance to hear more about Google\'s developer products.',
            'start' => array(
                'dateTime' => '2015-05-28T09:00:00-07:00',
                'timeZone' => 'America/Los_Angeles',
            ),
            'end' => array(
                'dateTime' => '2015-05-28T17:00:00-07:00',
                'timeZone' => 'America/Los_Angeles',
            ),
            'recurrence' => array(
                'RRULE:FREQ=DAILY;COUNT=2'
            ),
            'attendees' => array(
                array('email' => 'lpage@example.com'),
                array('email' => 'sbrin@example.com'),
            ),
            'reminders' => array(
                'useDefault' => FALSE,
                'overrides' => array(
                    array('method' => 'email', 'minutes' => 24 * 60),
                    array('method' => 'popup', 'minutes' => 10),
                ),
            ),
        );
	$this->googlecalendar->insert($data);- You can also set some option parameters:
 
$this->googlecalendar->singleEvents(true)->showDeleted(false)->showHiddenInvitations(false)
            ->orderBy("startTime")->timeMin(mktime($hour, $minute, $second, $month, $day, $year))
            ->timeMax(mktime($hour, $minute, $second, $month, $day, $year))
            ->updatedMin(mktime($hour, $minute, $second, $month, $day, $year))
            ->maxResults(10)
            ->getAll();Some tips:
This command will bring all the gogle services in your vendor folder and creates a lot of unnecessary files. composer require google/apiclient:^2.11
So if you only need some specific services and don't need files for other services like addmob,drive,youtube you can put this in composer and run composer update
"require": {
		"php": ">=5.3.7",
		"google/apiclient": "2.11"
	},
"scripts": {
		"post-update-cmd": "Google\\Task\\Composer::cleanup"
	},
	"extra": {
		"google/apiclient-services": [
			"Calendar"
		]
	},and run composer update
This will remove unnecessary service's files
For more details please checkout Google Calendar Php Docs
















