Google People API - получить списокPeopleConnections - PullRequest
0 голосов
/ 20 марта 2019

У меня проблема с Google API PHP.Мне нужно получить все контакты пользователя в моем приложении.Я использую официальный lib https://github.com/googleapis/google-api-php-client. Мой код, вдохновленный: 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());
        }
    }
}

, но в результате получается

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
  ]
}

Я также пытался

$service_contacts = new \Google_Service_People($client);

всегда нет результата, как будто у меня нет контактов.

Имеет ли это смысл для кого-то еще?

1 Ответ

0 голосов
/ 23 марта 2019

(Опубликовано от имени автора вопроса) .

Я забыл установить адрес электронной почты пользователя:

$service_contacts->getClient()->setSubject($email); //user Email 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...