Your code is almost working.
However, you are redirected to "work.html". Therefore, your event is not raised after authentication redirection. Also, setRedirectUri should correspond to what you entered in the Google API plus the console (see "URI Redirection") And it should be THIS because this file introduces an event after the redirect, (You do not need "work.html")
So your simple.php should look like this (ALSO change the "redirect URI" in Google Api to http://localhost/simple.php
, you need to specify the domain, but you can use localhost, in setRedirectUri you can specify the same thing)
<?php error_reporting(E_ALL); require_once 'google-api-php-client/src/Google_Client.php'; require_once 'google-api-php-client/src/contrib/Google_CalendarService.php'; session_start(); if ((isset($_SESSION)) && (!empty($_SESSION))) { echo "There are cookies<br>"; echo "<pre>"; print_r($_SESSION); echo "</pre>"; } $client = new Google_Client(); $client->setApplicationName("Google Calendar PHP Starter Application"); $client->setClientId('###'); $client->setClientSecret('###'); $client->setRedirectUri('http://###/index.php'); $client->setDeveloperKey('###'); $cal = new Google_CalendarService($client); if (isset($_GET['logout'])) { echo "<br><br><font size=+2>Logging out</font>"; unset($_SESSION['token']); } if (isset($_GET['code'])) { echo "<br>I got a code from Google = ".$_GET['code'];
Also, as @BigMacAttack has already said, you only need $authURL = $client->createAuthURL();
once only if getAccessToken
failed.
Happy Halloween -)
Change I cleaned up a lot of the code using work links for logging in and out, and log messages.
source share