【问题标题】:Multiple upload Google Contacts Api XML?多次上传 Google Contacts Api XML?
【发布时间】:2016-04-11 09:48:02
【问题描述】:

我正在用 PHP 开发一个应用程序,第一次需要上传 100 个联系人,我已经开发了一个基本应用程序,用于上传联系人,但它需要接近 1.5 秒处理请求:

        $before = microtime(true);
        $req = new Google_Http_Request("https://google.com/m8/feeds/contacts/" . $user_email . "/full/");
        $req->setRequestMethod("POST");
        $req->setPostBody($contact_xml);
        $req->setRequestHeaders(array('content-length' => strlen($contact_xml), 'GData-Version' => '3.0', 'content-type' => 'application/atom+xml; charset=UTF-8; type=feed'));

        $submit = $this->_gclient->getAuth()->authenticatedRequest($req);
        $sub_response = $submit->getResponseBody();
        $parsed = simplexml_load_string($sub_response);
        $client_id = explode("base/", $parsed->id);

        //Profiling
        $after = microtime(true);

我尝试连接我的条目两次或我需要的时间,但它不起作用:

$contact_xml.="
<atom:entry xmlns:atom='http://www.w3.org/2005/Atom'
    xmlns:gd='http://schemas.google.com/g/2005'
    xmlns:gContact='http://schemas.google.com/contact/2008'>
  <atom:category scheme='http://schemas.google.com/g/2005#kind'
    term='http://schemas.google.com/contact/2008#contact'/>
  ...
  <gContact:groupMembershipInfo deleted='false'
        href='http://www.google.com/m8/feeds/groups/".$user_email."/base/6'/>
</atom:entry>

我从谷歌得到的唯一信息是:

 [1] => SimpleXMLElement Object
    (
        [error] => SimpleXMLElement Object
            (
                [domain] => GData
                [code] => parseError
                [internalReason] => Parse Error
            )

    )

这就像...

  1. 我做错了什么吗,Google 是否提供任何异步请求
  2. 甚至可以多次上传 Google 联系人条目吗?
  3. 如果我使用单独的上传功能进行循环,对于 100 个联系人的数量来说需要太长时间,这就是问题的原因。

比你!

【问题讨论】:

  • Google 是否提供任何类型的异步请求?甚至可以多次上传谷歌联系人条目。文档是怎么说的?
  • 它什么也没说,我以前查阅过文档,但没有找到任何我问的原因。而且我认为,由于这里之前没有被问过,可能会引起人们的兴趣。
  • 如果它不在文档中,那么可能是因为它不受支持。联系人是旧的 Gdata API,它们没有新发现 API 的功能。您可能需要查看 gdata api 上的文档,看看批处理是否适用于联系人developers.google.com/gdata/docs/batch
  • 它看起来正是我所需要的,非常感谢你我会尽快进行测试,无法弄清楚谷歌如何不解决这个问题。我会发布解决方案以防万一:)
  • 如果你让它工作,回答你自己的问题,以便其他人可以看到如何做到这一点。

标签: php google-api google-api-php-client google-contacts-api google-data-api


【解决方案1】:

最后感谢 DalmTo,GData 的批处理功能 完美地解决了这个问题。 以下是您需要创建以使用批处理功能的提要示例:

<feed xmlns='http://www.w3.org/2005/Atom'
xmlns:gContact='http://schemas.google.com/contact/2008'
xmlns:gd='http://schemas.google.com/g/2005'
xmlns:batch='http://schemas.google.com/gdata/batch'>
<entry>
    <batch:id>create</batch:id>
    <batch:operation type='insert'/>
    <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/g/2008#contact'/>
    <gd:name>
    <gd:fullName>Example example</gd:fullName>
    <gd:givenName>Example</gd:givenName>
    <gd:familyName>Example</gd:familyName>
    </gd:name>
    <gd:email rel='http://schemas.google.com/g/2005#home' address='liz@gmail.com' primary='true'/>
</entry></feed>

然后你只需要复制你的条目,你需要循环的操作。 只是为了在您的联系人收件箱中创建联系人的建议,您需要添加:

<gContact:groupMembershipInfo deleted = 'false' href = 'http://www.google.com/m8/feeds/groups/" . $user_email . "/base/6' />

对 Google 的请求如下:

$req = new Google_Http_Request("https://www.google.com/m8/feeds/contacts/" . $user_email . "/full/batch/");

我希望这对某人有所帮助。

【讨论】:

  • base/6 中的 6 是什么?是 groupId 吗?你命名为 6 还是默认的?
猜你喜欢
  • 1970-01-01
  • 2011-09-20
  • 1970-01-01
  • 1970-01-01
  • 2013-10-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多