我正在尝试在“我的联系人”系统组中添加联系人。
我可以创建一个“没有组”的联系人(存储在“其他联系人”中) 请参阅代码: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";
}
但是当我在联系人创建的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";
}
是否可以直接在“我的联系人”系统组中创建联系人,或者是否有必要在第一时间创建联系人并在之后更新?
感谢您的帮助:)
答案 0 :(得分:0)
我自己找到了:)
要检索系统组URLID,唯一的方法是在GET REQUEST中设置v = 2:
https://www.google.com/m8/feeds/groups/".$this->_account."/full"?v=2&access_token=".$this->_access_token
通过添加:
创建联系人之后 <gContact:groupMembershipInfo deleted="false" href="'.$MyContactSystemGroup_urlid.'"/>