My goal is to insert events to a group calendar VIA PHP
- I have created an app on api console
- I have activated calendar API and created API KEY
- I have created a service account as described here
Here is my code:
class Googl_Cal{
public function __construct(){
$this->client = $this->get_client();
}
public function get_client()
{
putenv('GOOGLE_APPLICATION_CREDENTIALS=/' . dirname( __FILE__ ) . '/gcal_service_account.json');
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$scopes = [ Google_Service_Calendar::CALENDAR ];
$client->setScopes($scopes);
return $client;
}
public function create_event(){
$service = new Google_Service_Calendar( $this->client );
$calendarList = $service->calendarList->listCalendarList();
$calendarId = '';
$event = new Google_Service_Calendar_Event(
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' => '2018-01-31T09:00:00-07:00',
'timeZone' => 'Asia/Jerusalem',
),
'end' => array(
'dateTime' => '2018-01-31T17:00:00-07:00',
'timeZone' => 'Asia/Jerusalem',
),
'recurrence' => array(
'RRULE:FREQ=DAILY;COUNT=2'
),
'reminders' => array(
'useDefault' => FALSE,
'overrides' => array(
array('method' => 'email', 'minutes' => 24 * 60),
array('method' => 'popup', 'minutes' => 10),
),
),
)
);
$calendarId = 'primary';
$event = $service->events->insert($calendarId, $event);
print_r($event);
die();
}
}
After calling create_event(); Im getting an empty list on $calendarList