After you've completed the steps in Get Ready to Use the People API, you are ready to retrieve data by sending requests to the People API.
The following code samples demonstrate how to send a few simple requests:
- Get the user's connections.
- Get the person for the user.
- Get the person for a Google Account.
For a full list of methods, see the reference documentation.
Get the user's connections
To get a list of people in the user's contacts, use the following code:
Protocol
GET /v1/people/me/connections?personFields=names,emailAddresses HTTP/1.1 Host: people.googleapis.com
Java
ListConnectionsResponse response = peopleService.people().connections().list("people/me") .setPersonFields("names,emailAddresses") .execute(); List<Person> connections = response.getConnections();
Python
connections = people_service.people().connections() .list('people/me', personFields='names,emailAddresses')
PHP
$connections = $people_service->people_connections->listPeopleConnections( 'people/me', array('personFields' => 'names,emailAddresses'));
.NET
PeopleResource.ConnectionsResource.ListRequest peopleRequest = peopleService.People.Connections.List("people/me"); peopleRequest.PersonFields = "names,emailAddresses"; ListConnectionsResponse connectionsResponse = peopleRequest.Execute(); IList<Person> connections = connectionsResponse.Connections;
Get the person for the user
To get the user's profile, use the following code:
Protocol
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();
Get the person for a Google Account
To get the person information for any Google Account, use the following code:
Protocol
GET /v1/people/account_id?personFields=names,emailAddresses HTTP/1.1 Host: people.googleapis.com
Java
Person profile = peopleService.people().get("account_id") .setPersonFields("names,emailAddresses") .execute();
Python
profile = people_service.people() .get('account_id', personFields='names,emailAddresses')
PHP
$profile = $people_service->people->get( 'account_id', array('personFields' => 'names,emailAddresses'));
.NET
PeopleResource.GetRequest peopleRequest = peopleService.People.Get("account_id"); peopleRequest.PersonFields = "names,emailAddresses"; Person profile = peopleRequest.Execute();