Я пытаюсь установить связь между учетной записью календаря Google и API календаря Google, чтобы обновить базу данных MySQL на основе событий, содержащихся в календаре Google. Кажется, мой клиент настроен, и теперь мне нужно получить CalendarList, но тут у меня проблемы.
Я черпал вдохновение из того, что было сделано в quickstart.php и что объяснено в документации Google, чтобы попробовать некоторые тесты.
Проблема в том, что все мои запросы возвращают пустой результат, когда я использую метод getItems();
Мой код:
function getClient()
{
$client = new Google_Client();
$client->setApplicationName('Google Calendar API PHP synchroniser');
$client->setScopes(Google_Service_Calendar::CALENDAR_READONLY);
$client->setAuthConfig('Path/To/My/AccountService/File.json');
$client->setAccessType('online');
$client->setPrompt('MyCalendarWithMyData');
// Load previously authorized token from a file, if it exists.
// The file token.json stores the user's access and refresh tokens, and is
// created automatically when the authorization flow completes for the first
// time.
/*
$tokenPath = 'token.json';
if (file_exists($tokenPath)) {
$accessToken = json_decode(file_get_contents($tokenPath), true);
$client->setAccessToken($accessToken);
}
// If there is no previous token or it's expired.
if ($client->isAccessTokenExpired()) {
// Refresh the token if possible, else fetch a new one.
if ($client->getRefreshToken()) {
$client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
} else {
//I don't know what to put here.
}
}
*/
return $client;
}
$client = getClient(); // based on quickstart.php
$service = new Google_Service_Calendar($client);// from the sample on documentation
$calendarList = $service->calendarList->listCalendarList();
$calendars=$calendarList->getItems();
var_dump($calendars);
Моя цель - когда я получил список календарей, чтобы получить каждое событие относительно каждого календаря в списке календарей, чтобы обновить мою базу данных. Спасибо Г.Г.
PHP $client->setAuthConfig('My/Path/To/My/AccountService/File.json');
- person Galaxy Ghost   schedule 15.05.2019