dqphg40600 2011-05-26 07:38
浏览 113
已采纳

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

I have an application using zend_gdata and create contact with the code below.

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

Is there a possibility, a function to add a group to the contact just created?

  • 写回答

2条回答 默认 最新

  • douzhao4071 2011-10-11 12:47
    关注

    I have a big class and can't paste it all, you need to put this together somehow

    step 1)

    get all groups ( http://raiyaraj.wordpress.com/2008/09/17/gmail-gdata-contacts-group-via-proxy/) and find the id of your group or create it ( you can do it with zend framework) if it doesn't exist

    step 2)

    generate the 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);
    

    step 3)

    connect to gmail and execute the query

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

    notice that you return the edit link so that if you save it, you can update the contact or or check for modifications

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历