PHP library for the Google Contacts API (v3)
This package and its dependencies can be installed using composer
.
Just run composer require rapidwebltd/php-google-contacts-v3-api
.
- Install required dependencies. See the 'Dependencies' section above.
- Copy or rename
.config_blank.json
to.config.json
. Note the dot (.
) at the beginning of the file name. - Fill in the
clientID
,clientSecret
andredirectUri
in.config.json
.
- Note that
redirectUri
should be configure to point towards theredirect-handler.php
file. - The
clientID
andclientSecret
can be found in the Google Developers console at https://console.developers.google.com/ under 'APIs & auth' -> 'Credentials', after enabling the Contacts API.
- Go to
authorise-application.php
in a web browser. This should give you a URL to authorise your application for Google Contacts. - Go to the authorisation URL provided by the previous step.
- Accept the permissions requested on the page displayed. You should then be redirected back to the
redirect-handler.php
file. - The page generated by the
redirect-handler.php
file should then present you with a refresh token. Copy this into your.config.json
. - Setup is done!
For extensive usage instructions, please see the blog post I wrote on the subject here: http://www.rapidweb.biz/news/php-library-for-the-google-contacts-api-v3-06102593/
Also, take a look at the following files for basic examples of how to retrieve contacts. They can also be used to ensure you have currently associated your Google account with the library.
test.php
test_individual.php
Each method has optional argument for config file override. It is useful when you want to use work with multiple Google accounts at the same time.
$customConfig = (object) array(
'clientID' => '<clientId which you get according to setup above>',
'clientSecret' => '<clientSecret which you get according to setup above>',
'redirectUri' => '<your redirect uri>',
'developerKey' => '<developer key>',
'refreshToken' => '<refresh token specific for google account>'
);
$contacts = ContactFactory::getAll($customConfig);
You have to define all variables as the original config is completely ignored. To be more precise, it doesn't have to exist at all.