Google Contacts

The Google Contacts API allows client applications to view and update a user's contacts. Contacts are stored in the user's Google Account; most Google services have access to the contact list. Your client application can use the Google Contacts API to create new contacts, edit or delete existing contacts, and query for contacts that match particular criteria. To access contacts services you need to grab an access token by authenticating first. The analytics scope when generating a URL can be passed by simply setting 'contacts' to getLoginURL(). Figure 1 shows how we can obtain an access token for Google Contacts.

Figure 1. Authentication
session_start();

$auth = eden('google')->auth('[CLIENT_ID]', '[CLIENT_SECRET]', 'http://yourwebsite.com/auth', '[API_KEY]');

//if no code and no session
if(!isset($_GET['code']) && !isset($_SESSION['token'])) {
    //redirect to login
    $login = $auth->getLoginUrl('contacts');
    header('Location: '.$login);
    exit;
}

//Code is returned back from google
if(isset($_GET['code'])) {
    //save it to session
	$access = $auth->getAccess($_GET['code']);
    $_SESSION['token'] = $access['access_token'];
	
}

When we have our token we can then access the different service levels of Google Contacts.

Figure 2. Instantiate Contacts
$contacts = eden('google')->contacts($_SESSION['token']);
Figure 3. Contact Methods
Method Arguments Returns Description
$contacts->batch(); none Eden_Google_Contacts_Batch Returns Google contacts batch
$contacts->data(); none Eden_Google_Contacts_Batch Returns Google contacts data
$contacts->groups(); none Eden_Google_Contacts_Groups Returns Google contacts groups
$contacts->photo(); none Eden_Google_Contacts_Photo Returns Google contacts photo

© 2012 Openovate Labs. All rights reserved.