PHP code example of titeya / google-people-api

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

    

titeya / google-people-api example snippets


$people = new GooglePeople($googleOAuth2Handler);

// Retrieval all contacts
foreach($people->groupAll() as $group) {
    echo $group->resourceName.' - ';
    echo $group->name;
    echo PHP_EOL;
}

// Retrieve single contact (by resource name)
$group = $people->groupGet('contactGroups/c805502054287');

// Create new group
$group = new \stdClass();
$group->name="new group";
$people->groupSave($group);

// Delete group
$people->groupDelete("contactGroups/c805502054287");

// Retrieval all contacts
foreach($people->contactall() as $contact) {
    echo $contact->resourceName.' - ';
    if ($contact->names) {
        echo $contact->names[0]->displayName;
    }
    echo PHP_EOL;
}

// Retrieve single contact (by resource name)
$contact = $people->contactGet('people/c8055020007701654287');

// Create new contact
$contact = new Contact($people);
$contact->names[0] = new stdClass;
$contact->names[0]->givenName = 'Testy';
$contact->names[0]->familyName = 'McTest Test';
$contact->save();

// Update contact
$contact->names[0]->familyName = 'McTest';
$contact->save();

// Delete contact
$contact->delete();

php vendor/titeya/google-oauth-2-handler/src/setup.php