簡體   English   中英

Google通訊錄API忽略了userDefinedField設置

[英]Google contacts API is ignoring the userDefinedField setting

我試圖同時添加一個聯系人,包括一個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- CN 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

我設法弄清楚了。

我沒有指定要使用的API版本,因此使用以下代碼指定最新版本后,userDefinedField會根據需要出現在“聯系人”中。

$gdata->setMajorProtocolVersion(3);
$gdata->setMinorProtocolVersion(null);

希望這對其他有類似問題的人有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM