批量删除 PHP 的域共享联系人

Batch Delete Domain Shared Contacts With PHP

这是我使用的逻辑:

$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-lenght' 而不是 content-length.

不要发送条目中的任何内容以供删除,因为这不是必需的(也没有记录)。

$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);