【问题标题】:PHP - How to update/delete contact (google People) With PHPPHP - 如何使用 PHP 更新/删除联系人(google People)
【发布时间】:2018-06-19 00:45:50
【问题描述】:

三天我很沮丧,因为谷歌没有 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);
       }

    }

执行时出错:

异常“Google_Service_Exception”带有消息“{ “错误”: { “代码”:400, "message": "updatePersonFields 掩码是必需的。请指定一个或多个有效路径。有效路径记录在https://developers.google.com/people/api/rest/v1/people/update。", “错误”:[ { "message": "updatePersonFields 掩码是必需的。请指定一个或多个有效路径。有效路径记录在https://developers.google.com/people/api/rest/v1/people/update。", “域”:“全球”, “原因”:“错误请求” } ], “状态”:“INVALID_ARGUMENT”}}'

【问题讨论】:

标签: php google-api google-people-api


【解决方案1】:

您需要指定参数updatePersonFields。通过查看documentation 中的读取示例,似乎参数作为最后一个参数传递。它可能看起来应该是这样的:

$params = array('updatePersonFields' => 'names,emailAddresses');
$people_service->people->updateContact($google_id,$person,$params);

我没有测试过上面的,所以这可能不是确切的语法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多