简体   繁体   English

使用Google Contacts API在正确的系统组中添加联系人

[英]Add contact in correct systemgroup with Google Contacts API

I am trying to add contacts in "My Contacts" system group. 我正在尝试在“我的联系人”系统组中添加联系人。

I can create a contact "without group" (stored in "Other Contacts") see the code: http://pastebin.com/q0zksgM7 我可以创建“不带组”的联系人(存储在“其他联系人”中),请参见代码: http : //pastebin.com/q0zksgM7

{
        $acontact_formated = '
            <atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005">
                <atom:category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/contact/2008#contact"/>
                <gd:name>
                    <gd:givenName>'.$acontact["givenName"].'</gd:givenName>
                     <gd:familyName>'.$acontact["sn"].'</gd:familyName>
                     <gd:fullName>'.$acontact["displayName"].'</gd:fullName>
                </gd:name>
                <gd:email rel="http://schemas.google.com/g/2005#work" primary="true" address="'.$acontact["mail"].'" displayName="'.$acontact["displayName"].'" />
            </atom:entry>';

        $urlToSendReq = "https://www.google.com/m8/feeds/contacts/".$this->_account."/full/?access_token=".$this->_access_token;
        $bodyRequest = $acontact_formated;
        $headerRequest = array("Content-Type"=>"application/atom+xml", "GData-Version"=>"3.0");

        try
        {return myhttpservice::httpPost($urlToSendReq, $headerRequest, $bodyRequest);}
        catch (GuzzleHttp\Exception\ClientException $e)
        {return $e->getMessage();}

        return "OK";
    }

But when I add any "group id" in the ATOM of contact creation, I get a "Bad request": see previous code with modification: http://pastebin.com/gUCTs1K7 但是,当我在联系人创建的ATOM中添加任何“组ID”时,会收到“错误请求”:请参见先前的代码进行修改: http : //pastebin.com/gUCTs1K7

{
        $acontact_formated = '
            <atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005">
                <atom:category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/contact/2008#contact"/>
                <gd:name>
                    <gd:givenName>'.$acontact["givenName"].'</gd:givenName>
                     <gd:familyName>'.$acontact["sn"].'</gd:familyName>
                     <gd:fullName>'.$acontact["displayName"].'</gd:fullName>
                </gd:name>
                <gd:email rel="http://schemas.google.com/g/2005#work" primary="true" address="'.$acontact["mail"].'" displayName="'.$acontact["displayName"].'" />
                <gContact:groupMembershipInfo deleted="false" href="http://www.google.com/m8/feeds/groups/'.$this->_account.'/base/'.$this->MySystemContactGroupId.'"/>
            </atom:entry>';

        $urlToSendReq = "https://www.google.com/m8/feeds/contacts/".$this->_account."/full/?access_token=".$this->_access_token;
        $bodyRequest = $acontact_formated;
        $headerRequest = array("Content-Type"=>"application/atom+xml", "GData-Version"=>"3.0");

        try
        {return myhttpservice::httpPost($urlToSendReq, $headerRequest, $bodyRequest);}
        catch (GuzzleHttp\Exception\ClientException $e)
        {return $e->getMessage();}

        return "OK";
    }

Is it possible to create a contact directly in "My Contacts" system group, or is it necessary to create in 1st time the contact and update afterwards ? 是否可以直接在“我的联系人”系统组中创建联系人,还是必须在第一次创建联系人并随后进行更新?

Thanks for your help :) 谢谢你的帮助 :)

I found by myself :) 我自己发现的:)

To retrieve system group URLID the only way is to set v=2 in GET REQUEST: 要检索系统组URLID,唯一的方法是在GET REQUEST中设置v = 2:

https://www.google.com/m8/feeds/groups/".$this->_account."/full"?v=2&access_token=".$this->_access_token

After you can create a Contact by adding: 在您可以通过添加以下内容创建联系人后:

<gContact:groupMembershipInfo deleted="false" href="'.$MyContactSystemGroup_urlid.'"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM