0
我有一個PHP文件,將在我的Google日曆中成功創建一個事件從數據發佈從我的CRM,但是,我找不到任何文檔如何可以檢索它剛剛創建的事件的ID並返回一個JSON數據字符串。如何在PHP中創建事件後檢索Google日曆事件ID
這是我目前的PHP文件。
<?php
require_once __DIR__ . '/google-api-php-client/src/Google/autoload.php';
$summary = $_POST["summary"];
$location = $_POST["location"];
$description = $_POST["description"];
$startdatetime = $_POST["startdatetime"];
$enddatetime = $_POST["enddatetime"];
$client_email = '[email protected]';
$private_key = file_get_contents('xxxxxx.p12');
$scopes = array('https://www.googleapis.com/auth/calendar');
$user_to_impersonate = '[email protected]';
$credentials = new Google_Auth_AssertionCredentials(
$client_email,
$scopes,
$private_key,
'notasecret', // Default P12 password
'http://oauth.net/grant_type/jwt/1.0/bearer', // Default grant type
$user_to_impersonate
);
$client = new Google_Client();
$client->setAssertionCredentials($credentials);
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion();
}
$event = new Google_Service_Calendar_Event(array(
'summary' => $summary,
'location' => $location,
'description' => $description,
'start' => array(
'dateTime' => $startdatetime,
'timeZone' => 'America/Los_Angeles',
),
'end' => array(
'dateTime' => $enddatetime,
'timeZone' => 'America/Los_Angeles',
),
'reminders' => array(
'useDefault' => FALSE,
),
));
$service = new Google_Service_Calendar($client);
$calendarId = '[email protected]';
$event = $service->events->insert($calendarId, $event);