PHP Classes

File: GoogleLogin.php

Recommend this page to a friend!
  Classes of Stefan Kientzler   PHP Google Contacts API   GoogleLogin.php   Download  
File: GoogleLogin.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: 7 months ago
Size: 932 bytes
 

Contents

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

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

require_once
'autoloader.php';

/**
 * Call the google Oauth2 authentication.
 * This call first shows the google login form before the consent of the user
 * to grant access to the requested resource(s) (-> the 'scope') is asked.
 *
 * If access is granted, a auth code to get required tokens is passed to the
 * configured redirect URI.
 *
 * @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());
$oClient->addScope(GContacts::CONTACTS);
$oClient->addScope(GContacts::CONTACTS_OTHER_READONLY);

$strAuthURL = $oClient->buildAuthURL();

header('Location: ' . filter_var($strAuthURL, FILTER_SANITIZE_URL));