PHP Classes

File: GoogleOauth2Callback.php

Recommend this page to a friend!
  Classes of Stefan Kientzler   PHP Google Contacts API   GoogleOauth2Callback.php   Download  
File: GoogleOauth2Callback.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Google Contacts API
Access Google contacts with the Google People API
Author: By
Last change:
Date: 1 year ago
Size: 823 bytes
 

Contents

Class file image Download
<?php
declare(strict_types=1);

use
SKien\Google\GClient;
use
SKien\Google\GSecrets;

require_once
'autoloader.php';

/**
 * This script is called by the google authentication.
 *
 * The code passed to this script is used to fetch the
 * access/refresh token that is needed to call the API
 *
 * This is the redirect URI for the used client
 *
 * @author Stefanius <s.kientzler@online.de>
 * @copyright MIT License - see the LICENSE file for details
 */
$oSecrets = new GSecrets(GSecrets::TOKEN_FILE);
$oClient = new GClient();
$oClient->setOAuthClient($oSecrets->getClientSecrets());
if (
$oClient->fetchTokens($_GET['code'])) {
   
$oSecrets->saveRefreshToken($oClient->getRefreshToken());
   
$oSecrets->saveAccessToken($oClient->getAccessToken());
   
header('Location: ./ContactList.php');
}