- 我正在使用 Google API PHP客户端库 v2.1.3 https://github.com/google/google-api-php-client
- 我正在关注以下文档域共享联系人 https://developers.google.com/admin-sdk/domain-shared-contacts/#Deleting
- 我正在关注批次加工指南 https://developers.google.com/gdata/docs/batch#delete-operations用于删除
这是我正在使用的逻辑:
$xmlBuild = "<feed xmlns='http://www.w3.org/2005/Atom'
xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'
xmlns:batch='http://schemas.google.com/gdata/batch'
xmlns:gd='http://schemas.google.com/g/2005'
xmlns:gContact='http://schemas.google.com/contact/2008'>";
$xmlBuild .= "<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'>";
$xmlBuild .= "<batch:id>1</batch:id><batch:operation type='delete'/>";
$xmlBuild .= "<id>http://www.google.com/m8/feeds/contacts/my.domain/base/1b93ef80b806243</id>";
$xmlBuild .= "<link rel='edit' type='application/atom+xml' href='https://www.google.com/m8/feeds/contacts/my.domain/full/1b93ef80b806243/1812952240373020'/>";
$xmlBuild .= "</entry>";
$xmlBuild .= "</feed>";
$len = strlen($xmlBuild);
$options = array(
"headers" => array(
"Content-type" => "application/atom+xml; charset=UTF-8;",
"Content-lenght" => $len
),
"body" => $xmlBuild
);
$httpClient = $client->authorize();
$request = $httpClient->delete("https://www.google.com/m8/feeds/contacts/my.domain/full/batch", $options);
$response = $request->getBody()->getContents();
print_r($response); //This prints "Contact ID not found."
// ??? why ???
我很确定我所做的一切都是正确的。对我来说,这似乎是一种错误的行为。我已经搜索了任何显示如何执行此操作的示例,但均无济于事。这里有人能够确定我的逻辑是否有问题吗?预先感谢您可以提供的任何帮助。
P.D.插入方法就像一个魅力。问题仅在于删除联系人。我还没有测试更新方法,但它都指出几乎与删除相同。不批量删除是没有问题的。
看来错误是因为您发送了 DELETE http 动词而不是 POST。此外,条目中的 XML 命名空间属性也不是必需的。
顺便说一句,也许这是一个错字,你写了“content-len”ght' 而不是内容长度gth.
不要发送条目中的任何内容进行删除,因为这不是必需的(并且没有记录)。
$xmlBuild = "<feed xmlns='http://www.w3.org/2005/Atom'
xmlns:batch='http://schemas.google.com/gdata/batch'
xmlns:gd='http://schemas.google.com/g/2005'
xmlns:gContact='http://schemas.google.com/contact/2008'>";
$xmlBuild .= "<entry>";
$xmlBuild .= "<batch:id>1</batch:id><batch:operation type='delete'/>";
$xmlBuild .= "<id>http://www.google.com/m8/feeds/contacts/my.domain/base/1b93ef80b806243</id>";
$xmlBuild .= "</entry>";
$xmlBuild .= "</feed>";
$len = strlen($xmlBuild);
$options = array(
"headers" => array(
"Content-type" => "application/atom+xml; charset=UTF-8;",
"Content-length" => $len
),
"body" => $xmlBuild
);
$httpClient = $client->authorize();
$request = $httpClient->post("https://www.google.com/m8/feeds/contacts/my.domain/full/batch", $options);
// or $request = $httpClient->sendRequest('POST', "https://www.google.com/m8/feeds/contacts/my.domain/full/batch", $options);
$response = $request->getBody()->getContents();
print_r($response);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)