[英]How to read the contact data as returned by the Google People API using PHP
I am new to the google API and would like to use the People API for obtaining all the contacts of a user. 我是google API的新手,并且想使用People API获取用户的所有联系人。 It works, I can authenticate the user and I call the People API as follows:
它可以正常工作,我可以验证用户身份,然后按以下方式调用People API:
$contacts = $peopleService->people_connections->listPeopleConnections('people/me');
foreach ($contacts as $contactItem) {
$this->print_r2($contactItem);
}
But I obtain an object of type Google_Service_People_ListConnectionsResponse: 但是我获得了Google_Service_People_ListConnectionsResponse类型的对象:
Google_Service_People_ListConnectionsResponse Object
(
[collection_key:protected] => connections
[internal_gapi_mappings:protected] => Array
(
)
[connectionsType:protected] => Google_Service_People_Person
[connectionsDataType:protected] => array
[nextPageToken] =>
[nextSyncToken] => CPDp4aW_KhIBMRjuEioECAAQAQ
[modelData:protected] => Array
(
[connections] => Array
(
[0] => Array
(
[resourceName] => people/c3422388075840417635
[etag] => AgD+4rTZF6o=
[metadata] => Array
(
[sources] => Array
(
[0] => Array
(
[type] => CONTACT
[id] => 2fc3d288898002f63
[etag] => #AgD+4rTZF6o=
)
)
[deleted] => 1
[objectType] => PERSON
)
)
[1] => Array
(
[resourceName] => people/107483842333347794768
[etag] => btQbbIVcGJ4=
[metadata] => Array
(
[sources] => Array
(
[0] => Array
(
[type] => CONTACT
[id] => 715e58866e51e374
[etag] => #TW+s5999ANk=
)
[1] => Array
(
[type] => PROFILE
[id] => 107483842299147794768
)
)
[objectType] => PERSON
)
[names] => Array
(
[0] => Array
(
[metadata] => Array
(
[primary] => 1
[source] => Array
(
[type] => CONTACT
[id] => 715e50000e51e374
)
)
[displayName] => xxxxxxxx
[familyName] => xxxxxx
[givenName] => xxxxxxxxx
[displayNameLastFirst] => xxxxx, xxxxx
)
[1] => Array
(
[metadata] => Array
(
[source] => Array
(
[type] => PROFILE
[id] => *************************
)
)
[displayName] => xxxxxxxxxx
[familyName] => xxxxx
[givenName] => xxxxxxx
[displayNameLastFirst] => xxxxx, xxxxxxx
)
)
... . …… ..... ...
..... ...
My question is kinda stupid: how do I read, using the PHP client library, the [modelData:protected] array so I can the resulting [connections]. 我的问题有点愚蠢:我如何使用PHP客户端库读取[modelData:protected]数组,以便获得结果的[连接]。
I'm having the same issues as you, the documentation on Google's developer site seems to be incorrect given that the repo explicitly states to use the v1 branch. 我遇到了与您相同的问题,由于回购协议明确声明要使用v1分支,因此Google开发者网站上的文档似乎不正确。
This is what I've hacked together so far, it's bad code, but hopefully it will help you: 到目前为止,这是我共同研究的内容,它是错误的代码,但希望它将对您有所帮助:
$connections = $service->people_connections->listPeopleConnections('people/me', array(
'pageSize' => 500,
'requestMask.includeField' => 'person.names,person.phoneNumbers'
));
foreach($connections->connections as $contact){
echo("{$contact[names][0][displayName]}<br/>");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.