googleapis / googleapis/google-api-php-client-services

PeopleService->get returns no data

Open
#5,591 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
1.3k
Forks
320
Avg merge
2h 32m
Merged PRs (30d)
193

Description

`PeopleService->get` returns no data, especially when trying to get the user's photo.

#### Environment details

- OS: Linux
- PHP version: 8.1
- Package name and version: this project -> latest

#### Code example

```php
$client = new Client([
'credentials' => (new GCEDWDCredentials(
scope: implode(' ', [
Directory::ADMIN_DIRECTORY_USER_READONLY,
PeopleService::DIRECTORY_READONLY,
]),
))->setSubject(env('GSUITE_ADMIN_IMPERSONATE')),
]);

$user = (new Directory($client))->users->get($this->email, ['projection' => 'full']);
$person = (new PeopleService($client))->people->get('people/'.$user->getId(), ['personFields' => 'photos']);

$result = [
'full_name' => $user->getName()->getFullName(),
'thumbnail' => ($person->getPhotos()[0] ?? null)?->getUrl() ?? '/propman/images/default_avatar.jpg',
];
```

This works in Go using the same credentials:

```go
result, err := srv.Users.Get(email).Projection("full").Do()
if err != nil {
return nil, fmt.Errorf("GetUserInfo: User Info API Call (%s): %s", email, err)
}

name := result.Name.FullName

person, err := pplsrv.People.Get("people/" + result.Id).PersonFields("photos").Do()
if err != nil {
return nil, fmt.Errorf("GetUserInfo: Person Info API Call (%s:%s): %s", email, result.Id, err)
}

var thumbnail string
if len(person.Photos) > 0 {
thumbnail = person.Photos[0].Url
} else {
thumbnail = "/static/img/placeholder.jpg"
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.