php - 使用 Zend_GData 和 Google Contacts API 将联系人添加到群组

标签 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');
$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/

相关文章:

javascript - navigator.contacts.find 不工作(cordova/phonegap)

php - 如何使用 Zend/PHP 插入非默认的 Google 日历

php - 基于有条件设置的变量,否决从右到左书写语言的 CSS 对齐方式

php - ajax 请求的数据未存储到 $_POST 数组中

PHP 表单不发送到同一服务器上的电子邮件地址

android - 如何在 Android 4.2 中将联系人组添加到我自己的帐户

youtube - 在Youtube GData Youtube类中搜索多个关键字

gdata-api - 如何将 Blogger 用户名转换为数字 ID

Android 的 PHP 套接字

php - Mysql查询插入使用等号