【问题标题】:People api of People.get doesn't get names, photos for other userPeople.get 的 People api 没有获取其他用户的姓名、照片
【发布时间】: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。

期待您的支持和回复。

非常感谢您!

【问题讨论】:

标签: api flutter-web google-people-api


【解决方案1】:

我在较新的 People API 的一些部分中也注意到了这一点。 people.listDirecory 端点似乎坏了。较旧的已弃用 olderContacts.list 效果更好,但已弃用。

奇怪的是people.searchDirectoryPeople 按预期工作并显示readMask 中的每个字段,但您需要提供搜索(显然没有通配符选项)。使用完全相同的readMask 调用people.listDirectoryPeople 会省略大多数字段。我不确定people.listDirectoryPeople 是否需要不同的范围或什么,但似乎记录的这个 api 肯定有问题 - 除非有人能指出我们在某处丢失的另一个文档?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-12
    • 2015-02-19
    • 2012-08-27
    • 2019-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-06
    相关资源
    最近更新 更多