I have a question about the Google Calendar API.
I get the Google Calendar API with PHP and created the new event with service account.
If I read the calendar on php progrum
again, only the schedule written from php with service account can not be load.
What is the cause of the problem?
is it a specification that php can not read in a schedule created from php with a service account?
Setting information:
I am using autoload.php of google-api-php-client-1-master.
It is Google calendar V3.
In the calendar ID, the shared e-mail account (service account) is given the "schedule change authority" and can be written to the calendar.
The schedule that the owner directly created on Google Calendar can be read by php progrum, but the schedule created by php with the service account can not be load.
My code
//read event
$json_path = '../json/XXXX-123465789.json';
$json_string = file_get_contents($json_path, true);
$json = json_decode($json_string, true);
$private_key = $json['private_key'];
$client_email = $json['client_email'];
$scopes = array(Google_Service_Calendar::CALENDAR);
$credentials = new Google_Auth_AssertionCredentials(
$client_email,
$scopes,
$private_key
);
$client = new Google_Client();
$client->setApplicationName("Google Calendar PHP API");
$client->setAssertionCredentials($credentials);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion();
}
$service = new Google_Service_Calendar($client);
$read_start = mktime(0, 0, 0, 4, 10, 2017);
$read_end = mktime(0, 0, 0, 4, 17, 2017);
$calendarId = '[email protected]';
$optParams = array(
'maxResults' => 99,
'orderBy' => 'startTime',
'singleEvents' => TRUE,
'timeMin' => date('c', $read_start_date),
'timeMax' => date('c', $read_end_date),
);
$results = $service->events->listEvents($calendarId, $optParams);
//create event
$json_path = './json/xxx-123456789.json';
$json_string = file_get_contents($json_path, true);
$json = json_decode($json_string, true);
$calendarId = '[email protected]';
$private_key = $json['private_key'];
$client_email = $json['client_email'];
$scopes = array(Google_Service_Calendar::CALENDAR);
$credentials = new Google_Auth_AssertionCredentials(
$client_email,
$scopes,
$private_key
);
$client = new Google_Client();
$client->setApplicationName("Google Calendar");
$client->setAssertionCredentials($credentials);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion();
}
$service = new Google_Service_Calendar($client);
$meeting_end_time = _get_sum_time($set_time,$meeting_time);
$event = new Google_Service_Calendar_Event(array(
'summary' => 'created by service account',
'start' => array(
'dateTime' => '2017-04-04T00:12:00+09:00',
'timeZone' => 'Asia/Tokyo',
),
'end' => array(
'dateTime' => '2017-04-04T00:13:00+09:00',
'timeZone' => 'Asia/Tokyo',
),
));
$event = $service->events->insert($calendarId, $event);
However, the creator of the event is created by address of the service account, not the owner's mail account.
Could you tell me this answer?