Leer perfiles

Una vez que completes los pasos en Prepárate para usar la API de People, estarás listo para leer los datos de los perfiles.

En las siguientes muestras de código, se indica cómo enviar algunas solicitudes simples. Para ver una lista completa de métodos, consulta la documentación de referencia.

Obtén la persona para el usuario autenticado

Para obtener el perfil del usuario, usa el siguiente código:

Protocolo

GET /v1/people/me?personFields=names,emailAddresses HTTP/1.1
Host: people.googleapis.com

Java

Person profile = peopleService.people().get("people/me")
    .setPersonFields("names,emailAddresses")
    .execute();

Python

profile = people_service.people()
    .get('people/me', personFields='names,emailAddresses')

PHP

$profile = $people_service->people->get(
    'people/me', array('personFields' => 'names,emailAddresses'));

.NET

PeopleResource.GetRequest peopleRequest =
    peopleService.People.Get("people/me");
peopleRequest.PersonFields = "names,emailAddresses";
Person profile = peopleRequest.Execute();

Solicita a la persona un ID de Cuenta de Google

Para obtener la información de la persona para un ID de Cuenta de Google, usa el siguiente código:

Protocolo

GET /v1/people/account_id?personFields=names,emailAddresses HTTP/1.1
Host: people.googleapis.com

Java

Person profile = peopleService.people().get("people/account_id")
    .setPersonFields("names,emailAddresses")
    .execute();

Python

profile = people_service.people()
    .get('people/account_id', personFields='names,emailAddresses')

PHP

$profile = $people_service->people->get(
    'people/account_id', array('personFields' => 'names,emailAddresses'));

.NET

PeopleResource.GetRequest peopleRequest =
    peopleService.People.Get("people/account_id");
peopleRequest.PersonFields = "names,emailAddresses";
Person profile = peopleRequest.Execute();