我正在尝试向Google联系人中的群组添加联系人。当我在Google的“OAuth 2.0游乐场”中试用它时,#34;它可以工作,但是从我的网络应用程序,完全相同的标题,发布方法和正文,我得到了错误400:错误请求"。
这是我的代码(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);
当我遗漏groupMembershipInfo位时,它可以工作。
勒夫
答案 0 :(得分:1)
发现它:不要忘记添加xmlns:gContact =&#34; schemas.google.com/contact/2008"在你的xml中,它看起来像:
<?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> ...