2011-05-26 129 views
3

我有一個使用zend_gdata的應用程序並使用下面的代碼創建聯繫人。使用Zend_GData和Google Contacts API將聯繫人添加到組中

$doc = new DOMDocument(); 
$doc->formatOutput = true; 
$entry = $doc->createElement('atom:entry'); 
$entry->setAttributeNS('http://www.w3.org/2000/xmlns/' ,'xmlns:atom', 'http://www.w3.org/2005/Atom'); 
$entry->setAttributeNS('http://www.w3.org/2000/xmlns/' , 'xmlns:gd', 'http://schemas.google.com/g/2005'); 
$doc->appendChild($entry); 

// add name element 
$name = $doc->createElement('gd:name'); 
$entry->appendChild($name); 

$fullName = $doc->createElement('gd:fullName', htmlentities($data->firstname . ' ' . $data->lastname)); 
$name->appendChild($fullName); 

// insert entry 
$entryResult = $gdata->insertEntry($doc->saveXML(), 'http://www.google.com/m8/feeds/contacts/default/full'); 

是否有可能將函數添加到剛創建的聯繫人中?

+0

你是什麼意思的「添加一組到聯繫人」?是「將聯繫人添加到羣組」嗎? – emaillenin 2011-05-26 07:50:20

回答

2

我有一個大的類,不能粘貼這一切,你需要把這個莫名其妙一起

步驟1)

獲得所有組(http://raiyaraj.wordpress.com/2008/09/17/gmail-gdata-contacts-group-via-proxy/),並找到ID您的組或創建它(你可以與Zend框架做),如果它不存在

步驟2)

生成xml

// create new entry 
     $doc = new DOMDocument(); 
     $doc->formatOutput = true; 
     $entry = $doc->createElement('atom:entry'); 
     $entry->setAttributeNS('http://www.w3.org/2000/xmlns/' , 'xmlns:atom', 'http://www.w3.org/2005/Atom'); 
     $entry->setAttributeNS('http://www.w3.org/2000/xmlns/' , 'xmlns:gd', 'http://schemas.google.com/g/2005'); 
     $entry->setAttributeNS('http://www.w3.org/2000/xmlns/' , 'xmlns:gContact', 'http://schemas.google.com/contact/2008'); 
     $doc->appendChild($entry); 

...add various stuff.... 
    $name = $doc->createElement('gd:name'); 
      $entry->appendChild($name); 
      $fullName = $doc->createElement('gd:fullName', $this->name); 
      $name->appendChild($fullName); 
..... 

     $group = $doc->createElement('gContact:groupMembershipInfo'); 
     $group->setAttribute('deleted' ,'false'); 
     $group->setAttribute('href' ,'http://www.google.com/m8/feeds/groups/' .urlencode($this->email) . '/base/'.$this->group_id); 
     $entry->appendChild($group); 

步驟3)

連接到Gmail和執行查詢

$service = $this->service; 
// perform login and set protocol version to 3.0 
$client = $service; 
$gdata = new Zend_Gdata($client); 
$gdata->setMajorProtocolVersion(3); 
$entryResult = $gdata->insertEntry($this->getXML(), 'https://www.google.com/m8/feeds/contacts/default/full'); 

return $entryResult->getLink('edit'); 

通知您返回編輯鏈接,這樣,如果你保存它,你可以更新聯繫或檢查修改

相關問題