我正在尝试添加一个联系人,同时包括一个 userDefinedField。下面的代码有效并添加了具有正确信息的联系人,但是缺少 userDefined 字段。如果我故意拼错其中一个属性,当我发布 api 时告诉我它缺少一个元素,但是如果我修复拼写错误,它不包括 userDefined 字段。
也许我错过了一些微小的东西,但我真的不明白为什么它会被忽略。有没有人有任何想法?
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");
我已经从以下帖子中获得了很多帮助,但没有看到任何解决问题的方法: http ://www.google.com/support/forum/p/apps-apis/thread?tid=22ec941b7ac4ffc1&hl= zh http://groups.google.com/group/google-contacts-api/browse_thread/thread/be92586871a56046/95ec69573ca0f490?pli=1 http://www.ibm.com/developerworks/opensource/library/x-phpgooglecontact/索引.html