【发布时间】:2021-10-28 21:37:12
【问题描述】:
尊敬的 Google People API 开发人员:
我正在使用https://developers.google.com/people/api/rest/v1/people/get api,但是使用resourceName="people/account_id" 无法获取其他用户的姓名、照片等信息。
但是当我使用resourceName="people/me"时,我可以获得我的姓名、照片等个人资料信息
web和flutter我也试过了,结果是一样的。
{
"resourceName": "people/110971898718679553920",
"etag": "%EgYBAgMuNz0aBAECBQc=",
"photos": [
{
"metadata": {
"primary": true,
"source": {
"type": "PROFILE",
"id": "110971898718679553920"
}
},
"url": "https://lh3.googleusercontent.com/a-/AOh14GgB8WckrOhYHm-R_Y6hugAEu7XxQ-ktNsmzYUQW=s100",
"default": true
}
]
}
我怎样才能得到这些信息?
我的代码示例如下
通过库调用人员 API
Future<Person> getPersonDetails(String peopleId) async {
final GoogleAuthClient googleAuthClient =
await GoogleProvider.provideGoogleAuthClient();
final PeopleServiceApi peopleServiceApi =
peopleDataProvider.getPeopleApi(googleAuthClient);
Person person = await peopleServiceApi.people
.get(peopleId, personFields: '(names,photos,urls,emailAddresses)');
return person;
}
通过 HttpClient 调用 People API
Future<http.Response> getByPeopleAPI(String accountId) async {
GoogleSignInAccount googleSignInAccount =
await GoogleProvider.provideGoogleSignInAccount();
GoogleSignInAuthentication googleSignInAuthentication =
await googleSignInAccount.authentication;
http.Client _client = http.Client();
_client.get(
Uri.parse(
"https://people.googleapis.com/v1/$accountId?personFields=names,photos"),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': 'Bearer ${googleSignInAuthentication.accessToken}',
},
).then((value) {
print(value?.body.toString());
});
}
注意:我从 google 活动 API 的 actor 属性中获得了 people/account_id。
期待您的支持和回复。
非常感谢您!
【问题讨论】:
-
这能回答你的问题吗? Method: people.get() does not return names
-
您是否启用了域范围委派?
标签: api flutter-web google-people-api