0

J'ai configuré le projet d'API de calendrier Google. J'utilise OAuth 2.0 pour accéder aux données des API Google Calendar avec l'écran de consentement.Client non autorisé API Google Calendar (Google_Service_Exception)

J'ai suivi le processus mentionné ici: https://developers.google.com/google-apps/calendar/quickstart/php

pendant que je suis en train de chercher tous les calendriers pour le compte Google autorisé. Je reçois l'erreur suivante:

<h1>Google_Service_Exception</h1> 
{ 
"error": "unauthorized_client", 
"error_description": "Unauthorized" 
} 

Voici le code pour récupérer la liste de tous les calendriers:

$client = $this->getGoogleCalenderClient($clientSecretPath); 

$accessToken = json_decode(file_get_contents($clientSecretPath), true); 

$client->setAccessToken($accessToken); 

if ($client->isAccessTokenExpired()) { 

    $client->fetchAccessTokenWithRefreshToken($client->getRefreshToken()); 
    $result = $s3Client->putObject([ 
     'Bucket' => $bucketName, 
     'Key' => $credentialsPath, 
     'Body' => json_encode($client->getAccessToken()) 
    ]); 
} 

$service = new Google_Service_Calendar($client); 

$calendarList = $service->calendarList->listCalendarList(); 


Est-ce que quelqu'un sait ce que ce qui se passe ici? Et comment puis-je corriger cette erreur?
Reconnaissant pour toute aide.

Répondre

0

Does anyone know what this is happening here? And how can I fix this error?

Si vous accédez à l'application en utilisant le compte de service,

vérifier ce Github et le document officiel de Google for domain-wide delegation.

Les étapes suivantes doivent être effectuées par un administrateur du domaine Google Apps:

  1. Go to your Google Apps domain’s Admin console.
  2. Select Security from the list of controls. If you don't see Security listed, select More controls from the gray bar at the bottom of the page, then select Security from the list of controls. If you can't see the controls, make sure you're signed in as an administrator for the domain.
  3. Select Advanced settings from the list of options.
  4. Select Manage third party OAuth Client access in the Authentication section.
  5. In the Client name field enter the service account's Client ID.
  6. In the One or More API Scopes field enter the list of scopes that your application should be granted access to. For example, if your application needs domain-wide access to the Google Drive API and the Google Calendar API, enter: https://www.googleapis.com/auth/drive , https://www.googleapis.com/auth/calendar .
  7. Click Authorize.