读取个人资料

完成开始使用 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();