PHP code example of chetansingh / calendar-manager
1. Go to this page and download the library: Download chetansingh/calendar-manager library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
session_start();
rManager\Services\CalendarManager;
$calendar = new CalendarManager([
'client_id' => 'google-client-id',
'client_secret' => 'google-client-secret',
'redirect_uri' => 'https://your-app.test/google-callback.php',
]);
if (empty($_GET['code'])) {
exit('Google authorization code missing.');
}
$token = $calendar->driver('google')->handleCallback($_GET['code']);
if (!empty($token['error'])) {
exit('Google auth failed: ' . ($token['error_description'] ?? $token['error']));
}
// Store this token for the logged-in user.
// In production, save it in your database, encrypted if possible.
$_SESSION['google_access_token'] = $token;
header('Location: /calendar.php');
exit;
$newToken = $calendar->driver('google')->refreshAccessToken($storedRefreshToken);
// Save the new access token details for the user.
// Keep the old refresh token if Google does not return a new one.