rafraichir le calendrier google api selon le user connecté

Par Robin saint georges, il y a 7 ans


Bonjour,

Voila je rencontre un petit problème avec mon code.

je fais en ce moment une application me demandant d'acceder au calendrier google de l'utilisateur connecté

Je fais le login à l'aide de hwio, et j'utiliser l'api google calendar

$path = $this->get('kernel')->getRootDir() . '\..\src\AppBundle\Resources\credentials.json'; $client = new Google_Client(); $client->setApplicationName('socialPlanningV2'); $client->setScopes(Google_Service_Calendar::CALENDAR_READONLY); try { $client->setAuthConfig($path); } catch (\Google_Exception $e) { } // 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. $pathJson = $this->get('kernel')->getRootDir() . '\..\app\.credentials\calendar.json'; $tokenPath = $pathJson; 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 { // Request authorization from the user. $authUrl = $client->createAuthUrl(); printf("Open the following link in your browser:\n%s\n", $authUrl); print 'Enter verification code: '; $authCode = trim(fgets(STDIN)); // Exchange authorization code for an access token. $accessToken = $client->fetchAccessTokenWithAuthCode($authCode); $client->setAccessToken($accessToken); // Check to see if there was an error. if (array_key_exists('error', $accessToken)) { throw new Exception(join(', ', $accessToken)); } } // Save the token to a file. if (!file_exists(dirname($tokenPath))) { mkdir(dirname($tokenPath), 0700, true); } file_put_contents($tokenPath, json_encode($client->getAccessToken())); } // Get the API client and construct the service object. $service = new Google_Service_Calendar($client); // Print the next 10 events on the user's calendar. $calendarId = 'primary'; $optParams = array( 'maxResults' => 10, 'orderBy' => 'startTime', 'singleEvents' => true, 'timeMin' => date('c'), ); $results = $service->events->listEvents($calendarId, $optParams); $events = $results->getItems();

Je recupère les events toujours pour le meme user, même après avoir login avec un autre

Aucune réponse