1. Go to this page and download the library: Download baffo/googleapi 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/ */
// app/config/packages/pongocms/googleapi/config.php
return array(
// OAuth2 Setting, you can get these keys in Google Developers Console
'oauth2_client_id' => '< YOUR CLIENT ID >',
'oauth2_client_secret' => '< YOUR CLIENT SECRET >',
'oauth2_redirect_uri' => 'http://localhost:8000/', // Change it according to your needs
...
);
// routes.php
Route::get('/', function()
{
if ( Input::has('code') )
{
$code = Input::get('code');
// authenticate with Google API
if ( GoogleAPI::authenticate($code) )
{
return Redirect::to('/protected');
}
}
// get auth url
$url = GoogleAPI::authUrl();
return link_to($url, 'Login with Google!');
});
Route::get('/logout', function()
{
// perform a logout with redirect
return GoogleAPI::logout('/');
});
Route::get('/protected', function()
{
// Get the google service (related scope must be set)
$service = GoogleAPI::getService('Calendar');
// invoke API call
$calendarList = $service->calendarList->listCalendarList();
foreach ( $calendarList as $calendar )
{
echo "{$calendar->summary} <br>";
}
return link_to('/logout', 'Logout');
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.