Php 使用Zend_GData和Google Contacts API向组中添加联系人
我有一个使用zend_gdata的应用程序,并使用下面的代码创建联系人Php 使用Zend_GData和Google Contacts API向组中添加联系人,php,contact,zend-gdata,Php,Contact,Zend Gdata,我有一个使用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'); $entr
$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');
是否有可能向刚创建的联系人添加组的功能?有可能。请参阅以下文档以了解相同的信息
我有一个很大的类,无法将其全部粘贴,您需要以某种方式将其组合在一起 步骤1) 获取所有组()并找到组的id,如果不存在,则创建它(可以使用zend framework) 步骤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');
请注意,您将返回编辑链接,以便在保存时可以更新联系人或检查修改您所说的“向联系人添加组”是什么意思?是否是“将联系人添加到组”@max4您是否可以发布您的源代码(或示例代码),以便对其他人有所帮助?