I folks,
I have the following code working to update NAME/FULNAME and EMAIL but i
have difficulties with update phone number or add phone numbers to a
existent contact.
Could anyone give me a hint.
<?php
// load Zend Gdata libraries
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Http_Client');
Zend_Loader::loadClass('Zend_Gdata_Query');
Zend_Loader::loadClass('Zend_Gdata_Feed');
// set credentials for ClientLogin authentication
$user = "[email protected]";
$pass = "secret";
// set ID of entry to update
// from <link rel=self>
$id =
'http://www.google.com/m8/feeds/contacts/vhandrade%40atlantalegalaid.org/full/2484fc090e9961c7';
try {
// perform login and set protocol version to 3.0
$client = Zend_Gdata_ClientLogin::getHttpClient(
$user, $pass, 'cp');
$client->setHeaders('If-Match: *');
$gdata = new Zend_Gdata($client);
$gdata->setMajorProtocolVersion(3);
// perform query and get entry
$query = new Zend_Gdata_Query($id);
$entry = $gdata->getEntry($query);
$xml = simplexml_load_string($entry->getXML());
/*
$doc = new DOMDocument();
$doc->formatOutput = true;
*/
// change name
$xml->name->fullName = 'John Smith';
$xml->name->givenName = 'John'; //FIRST NAME
$xml->name->familyName = 'Smith'; //LAST NAME
// change primary email address
foreach ($xml->email as $email) {
if (isset($email['primary'])) {
$email['address'] = '[email protected]';
}
}
$extra_header = array();
$extra_header['If-Match']='*';
// update entry
$entryResult =
$gdata->updateEntry($xml->saveXML(),$entry->getEditLink()->href,null,$extra_header);
echo 'Entry updated'; echo "===> ". $phone1 . "|===> ";
} catch (Exception $e) {
die('ERROR:' . $e->getMessage());
}
?>
--
You received this message because you are subscribed to the Google
Groups "Google Contacts, Shared Contacts and User Profiles APIs" group.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://code.google.com/apis/contacts/community/forum.html