- 我正在使用Google API PHP客户库v2.1.3
- 我正在关注域共享联系人的文档
- 我遵循删除的批处理处理指南
这是我正在使用的逻辑:
$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。插入方法就像魅力一样。问题仅在于删除联系人。我尚未测试更新方法,但这一切都与删除几乎相同。在不批处理的情况下进行删除没有问题。
似乎错误是因为您发送删除http动词而不是帖子。另外,不需要条目中的XML名称空间属性。
顺便说一句,也许这是一个错别字,您写了'content-len ght ',而不是content-len 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);