PHP - 如何 update/delete 联系(google 人)与 PHP
PHP - How to update/delete contact (google People) With PHP
3 天以来,我很沮丧,因为 google 没有 php 的教程。
(抱歉我的英语不好)
我在更新名称时遇到错误:
$client=client_google();
$google_id="people/c3062123412341234";
if ($client->getAccessToken() == "") return null;
$people_service = new Google_Service_PeopleService($client);
$person = new Google_Service_PeopleService_Person();
if($tipenya == "Cancel"){
$name = new Google_Service_PeopleService_Name();
$name->SetFamilyName("Keluarga Cemara");
$name->SetGivenName("Tampan");
$person->setNames($name);
$profile = $people_service->people->get(
$google_id,
array('personFields' => 'metadata'));
$etag = $profile->etag;
$person->setEtag($etag);
$person->setResourceName($google_id);
if($google_id !=''){
//$people_service->people->updatePersonField("names");
$people_service->people->updateContact($google_id,$person);
}
}else if($tipenya=="Delete"){
if($google_id !=''){
$person->setResourceName($google_id);
$people_service->people->deleteContact($person);
}
}
执行时出错:
exception 'Google_Service_Exception' with message '{
"error": {
"code": 400,
"message": "updatePersonFields mask is required. Please specify one or more valid paths. Valid paths are documented at https://developers.google.com/people/api/rest/v1/people/update.",
"errors": [
{
"message": "updatePersonFields mask is required. Please specify one or more valid paths. Valid paths are documented at https://developers.google.com/people/api/rest/v1/people/update.",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT" }}'
您需要指定参数updatePersonFields
。通过查看 documentation 中的读取示例,似乎参数作为最后一个参数传递。它可能应该看起来像:
$params = array('updatePersonFields' => 'names,emailAddresses');
$people_service->people->updateContact($google_id,$person,$params);
我没有测试过上面的内容,所以这可能不是准确的语法。
3 天以来,我很沮丧,因为 google 没有 php 的教程。 (抱歉我的英语不好)
我在更新名称时遇到错误:
$client=client_google();
$google_id="people/c3062123412341234";
if ($client->getAccessToken() == "") return null;
$people_service = new Google_Service_PeopleService($client);
$person = new Google_Service_PeopleService_Person();
if($tipenya == "Cancel"){
$name = new Google_Service_PeopleService_Name();
$name->SetFamilyName("Keluarga Cemara");
$name->SetGivenName("Tampan");
$person->setNames($name);
$profile = $people_service->people->get(
$google_id,
array('personFields' => 'metadata'));
$etag = $profile->etag;
$person->setEtag($etag);
$person->setResourceName($google_id);
if($google_id !=''){
//$people_service->people->updatePersonField("names");
$people_service->people->updateContact($google_id,$person);
}
}else if($tipenya=="Delete"){
if($google_id !=''){
$person->setResourceName($google_id);
$people_service->people->deleteContact($person);
}
}
执行时出错:
exception 'Google_Service_Exception' with message '{ "error": { "code": 400, "message": "updatePersonFields mask is required. Please specify one or more valid paths. Valid paths are documented at https://developers.google.com/people/api/rest/v1/people/update.", "errors": [ { "message": "updatePersonFields mask is required. Please specify one or more valid paths. Valid paths are documented at https://developers.google.com/people/api/rest/v1/people/update.", "domain": "global", "reason": "badRequest" } ], "status": "INVALID_ARGUMENT" }}'
您需要指定参数updatePersonFields
。通过查看 documentation 中的读取示例,似乎参数作为最后一个参数传递。它可能应该看起来像:
$params = array('updatePersonFields' => 'names,emailAddresses');
$people_service->people->updateContact($google_id,$person,$params);
我没有测试过上面的内容,所以这可能不是准确的语法。