[英]Google People API - get listPeopleConnections
I have a problem with the Google API PHP.我的 Google API PHP 有问题。 I need to get all the contacts of a user in my application.
我需要在我的应用程序中获取用户的所有联系人。 I use the official lib https://github.com/googleapis/google-api-php-client .
我使用官方库https://github.com/googleapis/google-api-php-client 。 My code, inspired from: https://developers.google.com/people/quickstart/php
我的代码,灵感来自: https : //developers.google.com/people/quickstart/php
$client->setScopes(
array(
\Google_Service_PeopleService::CONTACTS,
\Google_Service_PeopleService::CONTACTS_READONLY,
\Google_Service_PeopleService::USERINFO_PROFILE,
\Google_Service_PeopleService::USERINFO_EMAIL,
)
);
$service_contacts = new \Google_Service_PeopleService($client);
$optParams = array(
'pageSize' => 10,
'personFields' => 'names,emailAddresses',
);
$results = $service_contacts->people_connections->listPeopleConnections('people/me', $optParams);
if (count($results->getConnections()) == 0) {
echo "No connections found.<br>";
} else {
echo "contacts :<br>";
foreach ($results->getConnections() as $person) {
if (count($person->getNames()) == 0) {
echo "No names found for this connection<br>";
} else {
$names = $person->getNames();
$name = $names[0];
printf("%s<br>", $name->getDisplayName());
}
}
}
but the result is但结果是
Google_Service_PeopleService_ListConnectionsResponse {#712 ▼
#collection_key: "connections"
#connectionsType: "Google_Service_PeopleService_Person"
#connectionsDataType: "array"
+nextPageToken: null
+nextSyncToken: null
+totalItems: null
+totalPeople: null
#internal_gapi_mappings: []
#modelData: array:1 [▼
"connections" => []
]
#processed: array:1 [▼
"connections" => true
]
}
I also tried我也试过
$service_contacts = new \Google_Service_People($client);
always no result, as if I have no contacts.总是没有结果,就好像我没有联系。
Does this make sense to anyone else?这对其他人有意义吗?
(Posted on behalf of the question author) . (代表问题作者发表) 。
I forget to set the user email :我忘记设置用户电子邮件:
$service_contacts->getClient()->setSubject($email); //user Email
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.