Добавьте контакт в нужную системную группу с помощью API контактов Google

Я пытаюсь добавить контакты в системную группу «Мои контакты».

Я могу создать контакт «без группы» (хранится в «Другие контакты»)
увидеть код: 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 создания контакта, я получаю «Плохой запрос»:
см. предыдущий код с модификацией: 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

Решение

Я нашел сам 🙂

Чтобы получить URLID системной группы, единственный способ — установить v = 2 в GET REQUEST:

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

После вы можете создать контакт, добавив:

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

0

Другие решения

Других решений пока нет …