使用PHP批量删除域名共享联系人 [英] Batch Delete Domain Shared Contacts With PHP
问题描述
- 我使用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); //打印出找不到联系人ID。
// ???为什么?
我很确定我做的一切都正确。对我来说,这似乎是一个错误的行为。我已经搜索过任何示例,说明如何做到这一点,无济于事。有人能够确定我的逻辑是否有问题吗?提前感谢您提供任何帮助。
P.D。插入方法就像一个魅力。问题仅在于删除联系人。我还没有测试更新的方法,但它都指出与删除几乎相同。
看来错误是因为您发送DELETE http动词而不是一个帖子。另外,条目中的XML名称空间属性不是必需的。顺便说一下,也许这是一个错字,你写了'content-len ght '而不是content-len gth / strong>。
不要发送删除条目中的任何内容,因为它不是必需的(并且没有记录)。
$ 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://架构。 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->信息(https://www.google.com/m8/feeds/contacts/my.domain/full/batch,$ options);
//或$ request = $ httpClient-> sendRequest('POST',https://www.google.com/m8/feeds/contacts/my.domain/full/batch,$ options) ;
$ response = $ request-> getBody() - > getContents();
print_r($ response);
- I am using Google API PHP Client Library v2.1.3
- I am following the documentation for Domain Shared Contacts
- I am following the batch processing guidelines for delete
Here is the logic I'm using:
$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 ???
I'm pretty sure I am doing everything correct. To me,it seems a buggy behavior. I already searched for any example that shows how to do this to no avail. Is anyone here capable of determining if there is something wrong with my logic? Thanks in advance for any help that can be provided.
P.D. The insert method works like a charm. The problem is only with deleting the contacts. I haven't tested the update method yet but it all points out to be almost the same as the delete. There is no problem in doing the deletion without batching.
It seems the mistake is because you send a DELETE http verb instead of a POST. Also, the XML namespace attributes in the entry are not required.
By the way, maybe this is a typo, you wrote 'content-lenght' instead of content-length.
Don't send any content in the entry for deletions, as it's not required (and not documented).
$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);
这篇关于使用PHP批量删除域名共享联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!