Событие календаря не вставлено - PullRequest
0 голосов
/ 04 ноября 2019

Я должен работать в API вставки Календаря Google без входа в систему ... Когда я запускаю эту функцию, это время не создает события в моей учетной записи, но эта функция возвращает "УСПЕХ"

Также аутентификация хороша. Если вы знаете, пожалуйста, найдите решение для этого вопроса .. спасибо

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;
}

1 Ответ

2 голосов
/ 05 ноября 2019

Пожалуйста, добавьте ниже строки на ваш код

$scope = new Google_Service_Calendar_AclRuleScope($client); 
$rule = new Google_Service_Calendar_AclRule($client);
$scope->setType('user');
$scope->setValue( 'your Email' );
$rule->setRole( 'owner' );
$rule->setScope( $scope );
$result = $service->acl->insert('primary', $rule);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...