I'm trying to connect using the api of google using php to loggearme with the user of gmail and retrieve the calendars I have, for this I use this code. What I get is loggearme and that oauth2 I return the TOKEN but once I have this token I do not know how to use it to get the details of my google calendar.
Thank you
Settings.php
/* Google App Client Id */
define('CLIENT_ID', 'XXXXXXXX.apps.googleusercontent.com');
/* Google App Client Secret */
define('CLIENT_SECRET', 'XXXXXXX');
/* Google App Redirect Url */
define('CLIENT_REDIRECT_URL',
'http://localhost:8081/googleTesting/oauth2callback.php');
<html>
<head>....</head>
<body>
<a href="<?= 'https://accounts.google.com/o/oauth2/auth?scope=' . urlencode('https://www.googleapis.com/auth/userinfo.profile') . '&redirect_uri=' . urlencode(CLIENT_REDIRECT_URL) . '&response_type=code&client_id=' . CLIENT_ID . '&access_type=online' ?>">Login with Google</a>
<br>
</body>
</html>
Calendar.php
// We have access we can now create our service
if (isset($_SESSION['datosGoogle']['access_token'])) {
$client = new Google_Client();
$client->setAccessToken($_SESSION['datosGoogle']['access_token']);
print "LogOut";
$service = new Google_Service_Calendar($client);
$calendarList = $service->calendarList->listCalendarList();;
while(true) {
foreach ($calendarList->getItems() as $calendarListEntry) {
echo $calendarListEntry->getSummary()."
";
// get events
$events = $service->events->listEvents($calendarListEntry->id);
foreach ($events->getItems() as $event) {
echo "-----".$event->getSummary()."";
}
}
$pageToken = $calendarList->getNextPageToken();
if ($pageToken) {
$optParams = array('pageToken' => $pageToken);
$calendarList = $service->calendarList->listCalendarList($optParams);
} else {
break;
}
}
}