读取个人资料

完成准备使用 People API 中的步骤后,您就可以读取个人资料的数据了。

以下代码示例演示了如何发送一些简单的请求。如需查看完整的方法列表,请参阅参考文档

获取经过身份验证的用户的人员

如需获取用户的个人资料,请使用以下代码:

协议

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();

获取 Google 账号 ID 对应的用户

如需获取 Google 账号 ID 的用户信息,请使用以下代码:

协议

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();