Невозможно получить доступ к новым календарям Google, созданным с помощью API, с помощью учетной записи службы - PullRequest
0 голосов
/ 28 мая 2020

Мы используем Google Calendar API для создания календарей и управления ими от имени пользователей.

Для этого мы создаем календарь с таким правилом ACL:

$client = new Google_Client();
$client->setApplicationName(APPLICATION_NAME);
$client->setScopes(Google_Service_Calendar::CALENDAR);
$client->setAuthConfig('/.../oauth_secret.json');
$client->setRedirectUri(REDIRECT_URI);
$client->authenticate($_GET['code']);
$accessToken = $client->getAccessToken();
$client->setAccessToken($accessToken);
$service = new Google_Service_Calendar($client);

$calendar = new Google_Service_Calendar_Calendar();
$calendar->setSummary($calendarName);
$calendar->setTimeZone('Europe/Paris');
$newCalendar = $service->calendars->insert($calendar);
$calendarId = $newCalendar->getId();

$rule = new Google_Service_Calendar_AclRule();
$scope = new Google_Service_Calendar_AclRuleScope();
$scope->setType("user");
$scope->setValue("295093256...012ulkk4oklusjh8...@developer.gserviceaccount.com");
$rule->setScope($scope);
$rule->setRole("owner");
$service->acl->insert($calendarId, $rule);

Поэтому мы пытаемся получить доступ к календарю следующим образом:

$client = new Google_Client();
$client->setApplicationName(APPLICATION_NAME);
$client->setScopes(Google_Service_Calendar::CALENDAR);
$client->setAuthConfig('/.../private_key.json');
if ($client->isAccessTokenExpired()) $client->refreshTokenWithAssertion();

$this->service = new Google_Service_Calendar(client);

$calendar = $service->calendarList->get($calendarId);

До нескольких месяцев go, это работало отлично, но теперь мы получаем эту ошибку:

google_runner error: {
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "notFound",
    "message": "Not Found"
   }
  ],
  "code": 404,
  "message": "Not Found"
 }
}

Он по-прежнему работает для календарей, созданных ранее, но не для новых. Я прошу помощи, так как не могу найти причину.

Обратите внимание, что ACL правильно создан в новых календарях, как вы можете видеть здесь:

enter image description here

Есть идеи?

1 Ответ

1 голос
/ 29 мая 2020

Нашел!

Google больше не создает автоматически запись в списке календаря пользователя, когда вы создаете календарь.

Чтобы проверить, существует ли календарь, мне просто нужно было заменить:

$calendar = $service->calendarList->get($calendarId);

По

$calendar = $service->calendars->get($calendarId);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...