简体   繁体   English

如何将联系人添加到 google 联系人 api v3 中的组

[英]how can I add a contact to a group in google contacts api v3

I am trying to add a contact to a group in google contacts.我正在尝试将联系人添加到 google 联系人中的群组。 When I try it in Google's "OAuth 2.0 playground" it works, but from my web-application, with exactly the same headers, method of posting and body, I get "error 400: bad request".当我在 Google 的“OAuth 2.0 playground”中尝试它时,它可以工作,但是从我的网络应用程序中,使用完全相同的标头、发布方法和正文,我收到“错误 400:错误的请求”。

This is my code (php) :这是我的代码(php):

$contact = '<?xml version="1.0"?> 
<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005"> 
<gd:name> <gd:fullName>Jack Frost</gd:fullName> </gd:name> 
<gd:email address="jack.frost@example.com" rel="http://schemas.google.com/g/2005#home"/> 
<gd:organization rel="http://schemas.google.com/g/2005#work"> 
<gd:orgName>Winter Inc.</gd:orgName> </gd:organization> 
<gd:phoneNumber rel="http://schemas.google.com/g/2005#home"> (206)555-1213 </gd:phoneNumber> 
<gContact:groupMembershipInfo deleted="false" href="http://www.google.com/m8/feeds/groups/MY_EMAIL@gmail.com/base/MY_GROUP_ID"/> 
</atom:entry>';

$url = 'https://www.google.com/m8/feeds/contacts/MY_EMAIL@gmail.com/full/';
$method= 'POST';
$headers = ["Host" => "www.google.com", "Gdata-version" => "3.0","Content-length" => strlen($contact), "Content-type" => "application/atom+xml"]; 
$result = $googleService->request($url,$method,$contact,$headers);

When I leave out the groupMembershipInfo bit, it works.当我省略 groupMembershipInfo 位时,它会起作用。

Joachim约阿希姆

found it: don't forget to add xmlns:gContact="schemas.google.com/contact/2008" in your xml, so it looks something like:找到了:不要忘记在你的 xml 中添加 xmlns:gContact="schemas.google.com/contact/2008",所以它看起来像:

<?xml version="1.0"?> 
<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"> 

<gd:name> ...

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

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