Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PeopleService->get returns no data #5591

Open
iamacarpet opened this issue Sep 19, 2024 · 0 comments
Open

PeopleService->get returns no data #5591

iamacarpet opened this issue Sep 19, 2024 · 0 comments

Comments

@iamacarpet
Copy link

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

                $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:

	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"
	}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant