人员 API searchContacts 使用 google 人员服务

People API searchContacts using google people service

我尝试使用 Google People API 和 PHP client people service 添加新联系人,效果很好。我使用了以下代码,

$service = new Google_Service_PeopleService($client);
$person = new Google_Service_PeopleService_Person();
$name = new Google_Service_PeopleService_Name();
$name->setGivenName($_name);
$person->setNames($name);
$phone1 = new Google_Service_PeopleService_PhoneNumber();   
$phone1->setValue($_phone);
$phone1->setType('home');
$person->setPhoneNumbers($phone1);
$exe = $service->people->createContact($person)->execute;

现在我想检查特定的电子邮件是否已经存在,所以尝试了 API 的 searchContacts 方法。它在 API 资源管理器中工作正常。 参考: https://developers.google.com/people/api/rest/v1/people/searchContacts

但是当尝试使用以下代码时,

$service = new Google_Service_PeopleService($client);
$optParams = array('query'=>$_email,'pageSize' => 10, 'readMask' => 'emailAddresses', 'key'=>'XXXX');
try{
    $rslt = $service->people->searchContacts($optParams);
} catch(Exception $ex) {
    echo $e->getMessage();  
}

我收到以下错误,

PHP 致命错误:调用未定义的方法 Google_Service_PeopleService_Resource_People::searchContacts()

看错误我确定调用方法的方式是错误的。我已经搜索但无法获得正确的文档来指导该方向。 任何帮助将不胜感激。

谢谢

看起来我们不能使用人员服务对象调用 searchContacts,所以我使用 curl json 来让它工作。如果有人需要,我使用了以下代码。

$url_parameters = array('query'=>$_email,'pageSize' => 10, 'readMask' => 'names,phoneNumbers,emailAddresses,organizations', 'key'=>'XXXXX');

$url_calendars = 'https://people.googleapis.com/v1/people:searchContacts?'. http_build_query($url_parameters);

$ch = curl_init();      
curl_setopt($ch, CURLOPT_URL, $url_calendars);      
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer '. $access_token));   
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);    
$data = json_decode(curl_exec($ch), true); 
$http_code = curl_getinfo($ch,CURLINFO_HTTP_CODE);      
if($http_code != 200) 
    throw new Exception('Error : Failed to search contact');

return $data;

谢谢