PHP - 如何使用PHP更新/删除联系人(谷歌人)

时间:2018-06-19 00:45:50

标签: php google-api google-people

3天我很沮丧,因为谷歌没有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。”,           “域名”:“全球”,           “理由”:“badRequest”         }       ]       “status”:“INVALID_ARGUMENT”}}'

1 个答案:

答案 0 :(得分:1)

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

updatePersonFields

我尚未测试以上内容,因此可能不是确切的语法。