right here
. 完成域范围的委派后,可以使用以下方法完成任务:
<?php
session_start();
//INCLUDE PHP CLIENT LIBRARY
require_once 'google-api-php-client-2.0.3/vendor/autoload.php';
putenv('GOOGLE_APPLICATION_CREDENTIALS=yourkey.json'); // yourkey = the name of your json client secret file.
//set the required scopes
$scopes = array("https://www.googleapis.com/auth/calendar");
// Create client object
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope($scopes);
$client->setSubject("user@thedomain.com");
$cal = new Google_Service_Calendar($client);
$event = new Google_Service_Calendar_Event(array(
'summary' => 'Test Event',
'location' => 'Some Location',
'description' => 'Google API Test Event',
'start' => array(
'dateTime' => '2017-04-12T05:00:00-06:00'
),
'end' => array(
'dateTime' => '2017-04-12T05:25:00-06:00'
),
'reminders' => array(
'useDefault' => FALSE,
'overrides' => array(
array('method' => 'email', 'minutes' => 24 * 60),
array('method' => 'popup', 'minutes' => 10)
),
),
'attendees' => array(
array('email' => 'userone@domain.com'),
array('email' => 'usertwo@domain.com')
)
));
$calendarId = 'primary';
$event = $cal->events->insert($calendarId, $event, array('sendNotifications' => TRUE));
printf('Event created: %s<br>', $event->htmlLink);
?>
请注意:上面的示例是使用google api php客户端库执行的。有关其他示例,请参阅
official documentation
. 希望这有帮助!