我有一个使用 zend_gdata 的应用程序,并使用下面的代码创建联系。
$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');
有没有可能,一个功能可以将一个组添加到刚创建的联系人中?
最佳答案
我的类(class)很大,无法全部粘贴,你需要以某种方式将它们放在一起
步骤 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');
注意你返回了编辑链接,这样如果你保存它,你可以更新联系人或检查修改
关于php - 使用 Zend_GData 和 Google Contacts API 将联系人添加到群组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6135217/