I am trying to add a contact while at the same time including a userDefinedField. The code below works and adds the contact with the correct information however the userDefined field is missing. If I purposefully misspell one of the attributes, when I post the api falls over telling me it is missing an element, however if I fix the misspelling it does not include the userDefined Field.
Maybe I am missing something tiny but I really cannot see why it would simply be ignored. Does anyone have any ideas?
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Gapps');
Zend_Loader::loadClass('Zend_Gdata_Query');
$email = "<email>";
$password = "<password>";
$contactName = $requestData['name'];
$contactAddress = $requestData['email'];
$client = Zend_Gdata_ClientLogin::getHttpClient($email, $password,"cp");
$gdata = new Zend_Gdata($client);
$entry = $gdata->newEntry();
$extensionElements = $entry->getExtensionElements();
$extension = new Zend_Gdata_App_Extension_Element('email', null,'http://schemas.google.com/g/2005');
$attributes['address'] = array('name'=>'address', 'value' =>$contactAddress);
$attributes['rel'] = array('name'=>'rel', 'namespaceUri'=>null,'value' => 'http://schemas.google.com/g/2005#work');
$attributes['primary'] = array('name'=>'primary', 'namespaceUri' =>null, 'value' => 'true');
$extension->setExtensionAttributes($attributes);
$attributes = null;
// adds the new email extension element to the entry's exenstions elemensts array
array_push( $extensionElements, $extension );
$extension = new Zend_Gdata_App_Extension_Element('userDefinedField', null, 'http://schemas.google.com/contact/2008');
$attributes['key'] = array('name'=>'key', 'value' =>'customGUID');
$attributes['value'] = array('name'=>'value', 'value' => $this->guid());
$extension->setExtensionAttributes($attributes);
$attributes = null;
array_push( $extensionElements, $extension );
$extension = new Zend_Gdata_App_Extension_Element('groupMembershipInfo', null, 'http://schemas.google.com/contact/2008');
$attributes['deleted'] = array('namespaceUri'=>null,'name'=>'deleted', 'value' => 'false');
if ("manufacturers" == strtolower($contactgroup)) {
$attributes['href'] = array('namespaceUri'=>null,'name'=>'href', 'value' => $MANUFACTURER_GROUP_URI);
} elseif ("distributors" == strtolower($contactgroup)) {
$attributes['href'] = array('namespaceUri'=>null,'name'=>'href', 'value' => $DISTRIBUTOR_GROUP_URI);
} elseif ("clients" == strtolower($contactgroup)) {
$attributes['href'] = array('namespaceUri'=>null,'name'=>'href', 'value' => $CLIENT_GROUP_URI);
}
$extension->setExtensionAttributes($attributes);
array_push( $extensionElements, $extension );
$entry->setExtensionElements($extensionElements);
$entry->title = $gdata->newTitle($contactName);
$entry->setExtensionElements($extensionElements);
$entryResult = $gdata->insertEntry($entry,"http://www.google.com/m8/feeds/contacts/$email/full");
I have already received a lot of help from the following posts, but didn't see anything to fix the issue: http://www.google.com/support/forum/p/apps-apis/thread?tid=22ec941b7ac4ffc1&hl=en http://groups.google.com/group/google-contacts-api/browse_thread/thread/be92586871a56046/95ec69573ca0f490?pli=1 http://www.ibm.com/developerworks/opensource/library/x-phpgooglecontact/index.html
I managed to figure it out.
I was not specifying which version of the API to use, so as soon as I specified the latest version using the below code, the userDefinedField appeared in Contacts as required.
$gdata->setMajorProtocolVersion(3);
$gdata->setMinorProtocolVersion(null);
Hope this helps others with similar questions.