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