Update, 28th March 2018:
I've created a new package to manage Google Contacts based on the newer Google People API. If you're started a new project, I'd recommend you use this package instead of the one mentioned in my original post below.
You can find more details here: https://github.com/rapidwebltd/php-google-people-api
Original Post:
I had to work with this recently and after finding the lack of a Contacts service in the official PHP Google Client, I created a (MIT licensed) PHP library for the Google Contacts API.
One of the aims is to really simplify some of the process involved. So to answer your question, after setting up the library, the following code is all that is needed to retrieve contacts.
require_once '../../../vendor/autoload.php';
use rapidweb\googlecontacts\factories\ContactFactory;
$contacts = ContactFactory::getAll();
if (count($contacts)) {
echo 'Test retrieved '.count($contacts).' contacts.';
} else {
echo 'No contacts retrieved!';
}
The library needs a little work, but works well for basic contact retrieval, creation and updating. It can also be installed via composer
if needed. Just add the following to your composer.json
and run composer update
.
{
"require": {
"rapidwebltd/php-google-contacts-v3-api": "dev-master"
}
}
Further setup instructions and examples are available on GitHub.
GitHub Link: https://github.com/rapidwebltd/php-google-contacts-v3-api