为其他用户创建日历事件



我已经挖了一圈,我没有找到任何指向这一点的具体内容。 是否可以在其他用户日历中创建日历事件? 我们公司有谷歌应用,所以每个人都在我们的域中。 我找到的所有内容都指向其他用户需要批准日历事件。

我负责的最终结果是,当员工批准休假时,它会发送到员工和主管日历。 我确信那里有一些东西,我只是在任何地方都找不到它。

您需要使用服务帐户来模拟用户才能实现此目的。您可以在此处找到有关如何执行此授权的文档。完成全域委派后,您可以使用以下内容来完成任务:

<?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 客户端库执行的。有关其他示例,请参阅官方文档。希望这有帮助!

最新更新