1. Go to this page and download the library: Download tomshaw/google-api 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/ */
tomshaw / google-api example snippets
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use TomShaw\GoogleApi\GoogleClient;
use Illuminate\Http\Request;
class GoogleAuthController extends Controller
{
public function index(GoogleClient $client)
{
return redirect()->away($client->createAuthUrl());
}
public function callback(Request $request, GoogleClient $client)
{
$accessToken = $client->fetchAccessTokenWithAuthCode($request->get('code'));
$client->setAccessToken($accessToken);
return redirect()->route('homepage');
}
}
use TomShaw\GoogleApi\GoogleApi;
use TomShaw\GoogleApi\Exceptions\TokenNotFoundException;
try {
$events = GoogleApi::calendar()->listEvents();
} catch (TokenNotFoundException $e) {
return redirect()->away($e->authUrl);
}