2011-05-26 70 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'); 

通知您返回编辑链接,这样,如果你保存它,你可以更新联系或检查修改

相关问题