PHP code example of yidas / google-apiclient-helper

1. Go to this page and download the library: Download yidas/google-apiclient-helper 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/ */

    

yidas / google-apiclient-helper example snippets


$client = \yidas\google\apiHelper\Client::setClient()
    ->setApplicationName('Google API')
    ->setAuthConfig('/path/google_api_secret.json')
    ->setRedirectUri("http://{$_SERVER['HTTP_HOST']}" . dirname($_SERVER['PHP_SELF'])
    ->setAccessToken($accessToken)
    ->getClient();

if ($accessToken = ClientHelper::refreshAccessToken()) {
    // saveAccessToken($accessToken)
}

// People Service uses Google_Client from Client helper above
$contacts = \yidas\google\apiHelper\services\People::getSimpleContacts();


use yidas\google\apiHelper\Client;

$client = \yidas\google\apiHelper\Client::setClient([
        'applicationName' => 'Google API',
        'authConfig' => '/path/google_api_secret.json',
        'redirectUri' => "http://{$_SERVER['HTTP_HOST']}" . dirname($_SERVER['PHP_SELF'],
        ])
    ->getClient();

$client = \yidas\google\apiHelper\Client::setClient()
    ->setApplicationName('Google API')
    ->setAuthConfig('/path/google_api_secret.json')
    ->setRedirectUri("http://{$_SERVER['HTTP_HOST']}" . dirname($_SERVER['PHP_SELF'])
    ->getClient();

$client = new Google_Client();
$client->setAuthConfig('/path/google_api_secret.json');
\yidas\google\apiHelper\Client::setClient($client);

public static array|false refreshAccessToken()

$client = \yidas\google\apiHelper\Client::setClient()
    ->setApplicationName('Google API')
    ->setAuthConfig('/path/google_api_secret.json')
    ->setRedirectUri("http://{$_SERVER['HTTP_HOST']}" . dirname($_SERVER['PHP_SELF'])
    ->setAccessToken($accessToken)
    ->getClient();

// Simple way to get refreshed access token or false expired to skip
if ($accessToken = ClientHelper::refreshAccessToken()) {
    // saveAccessToken($accessToken)
}

public static array|false verifyAccessToken(string $accessToken=null)

public static array|false verifyScopes(array $scopes, string $accessToken=null)

$result = \yidas\google\apiHelper\Client::verifyScopes([
    'https://www.googleapis.com/auth/userinfo.profile',
]);

use \yidas\google\apiHelper\services\People as PeopleHelper;
\yidas\google\apiHelper\Client::setClient([...])

$contacts = PeopleHelper::getSimpleContacts();

use \yidas\google\apiHelper\services\People as PeopleHelper;

PeopleHelper::setClient($googleClient);
// PeopleHelper::method()...

$service = \yidas\google\apiHelper\services\People::getService();
// $service->people_connections->...

// Simple setValue() example
\yidas\google\apiHelper\services\People::newPerson
    ->setEmailAddresses('[email protected]')
    ->setPhoneNumbers('+886')
    ->setBiographies("I'm a note");

$gPhoneNumber = new Google_Service_PeopleService_PhoneNumber;
$gPhoneNumber->setValue('+886');
\yidas\google\apiHelper\services\People::setPhoneNumbers($gPhoneNumber);

\yidas\google\apiHelper\services\People::setPhoneNumbers(['value' => '+886']);

\yidas\google\apiHelper\services\People::setPhoneNumbers('+886');

public static array getContacts()

// Get formated list by Helper
$contacts = \yidas\google\apiHelper\services\People::getSimpleContacts();

Array
(
    [0] => Array
        (
            [id] => people/c26081557840316580
            [name] => Mr.Nick
            [email] => 
            [phone] => 0912 345 678
        )
    ...

public static Google_Service_PeopleService_Person createContact()

$person = \yidas\google\apiHelper\services\People::newPerson()
    ->setNames('Nick')
    ->setEmailAddresses('[email protected]')
    ->setPhoneNumbers('+886')
    ->createContact();

public static Google_Service_PeopleService_PeopleEmpty updateContact(array $optParams=null)

$person = \yidas\google\apiHelper\services\People::findByResource($resourceName)
    ->setNames('Nick')
    ->setEmailAddresses('[email protected]')
    ->setPhoneNumbers('+886')
    ->updateContact();

public static Google_Service_PeopleService_PeopleEmpty deleteContact(string $resourceName=null, array $optParams=[])

$person = \yidas\google\apiHelper\services\People::deleteContact($resourceName);

$person = \yidas\google\apiHelper\services\People::findByResource($resourceName)
    ->deleteContact();

try {} catch (\Google_Exception $e) {}

try {} catch (\Google_Service_Exception $e) {}