未插入日历事件

问题描述 投票:0回答:1

我必须在未登录的情况下使用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;
}

我必须在未登录的情况下使用google Calendar Insert API ...当我运行此功能时,该时间未在我的帐户上创建事件,但是该函数返回“ SUCCESS”,它的身份验证也不错。 ...

php google-calendar-api
1个回答
2
投票

请在您的代码的下方添加一行

© www.soinside.com 2019 - 2024. All rights reserved.