3

我有一个使用 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');

是否有一种可能性,可以将组添加到刚刚创建的联系人中?

4

2 回答 2

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');

请注意您返回了编辑链接,这样如果您保存它,您可以更新联系人或检查修改

于 2011-10-11T12:47:08.523 回答
0

是的,有可能。请参阅以下文档以获取相同的信息。

http://code.google.com/apis/contacts/docs/3.0/reference.html#groupMembershipInfo

于 2011-05-26T07:56:42.827 回答