我正在尝试将联系人添加到 google 联系人中的组。当我在 Google 的“OAuth 2.0 游乐场”中尝试它时,它可以工作,但是在我的网络应用程序中,具有完全相同的标题、发布方法和正文,我得到“错误 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 位时,它可以工作。
约阿希姆