我必须在未登录的情况下使用google Calendar Insert API ...当我运行此函数时,该时间并未在我的帐户上创建,但是该函数返回“ SUCCESS”
此外,身份验证还不错。如果您知道,请为该问题找到解决方案。谢谢
XAMPP Localhost
require_once ('C:/xampp/htdocs/java_google/google-api-
php/src/Google/autoload.php');
$client_id = 'XXXXX'; //Client ID
$service_account_name = 'XXXXXX'; //Email Address
$key_file_location = 'C:/xampp/htdocs/java_google/java-new-257718-
70d76ac18661.p12'; //key.p12
$client = new Google_Client(); //AUTHORIZE OBJECTS
$client->setapplicationName("Java New");
//INSTATIATE NEEDED OBJECTS (In this case,for freeBusy query,and Create
New Event)
$service = new Google_Service_Calendar($client);
$id = new Google_Service_Calendar_FreeBusyRequestItem($client);
$item = new Google_Service_Calendar_FreeBusyRequest($client);
$event = new Google_Service_Calendar_Event($client);
$startT = new Google_Service_Calendar_EventDateTime($client);
$endT = new Google_Service_Calendar_EventDateTime($client);
if (isset($_SESSION['service_token'])) {
$client->setaccessToken($_SESSION['service_token']);
}
$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
$service_account_name,array('https://www.googleapis.com/auth/calendar'),$key
);
$client->setassertionCredentials($cred);
if ($client->getauth()->isaccessTokenExpired()) {
$client->getauth()->refreshTokenWithAssertion($cred);
}
$_SESSION['service_token'] = $client->getaccessToken();
global $service;
global $event;
global $startT;
global $endT;
$calendarId = 'primary';
$summary = 'primary test test';
$location = 'chennai';
$description = 'chennai123';
$date = '2019-11-04T13:22:07+01:00';
$start = '2019-11-04T13:22:07+01:00';
$end = '2019-11-04T13:22:08+01:00';
$startT->setTimeZone("Europe/Rome");
$startT->setDateTime($date);
$endT->setTimeZone("Europe/Rome");
$endT->setDateTime($end);
$event->setSummary($summary);
$event->setLocation($location);
$event->setDescription($description);
$event->setStart($startT);
$event->setEnd($startT);
$insert = $service->events->insert($calendarId,$event);
if($insert) {
echo 'sucess';
return true;
}