Google 人 API - 按更新时间排序未按预期工作

Google People API - ordering by the update time not working as expected

我已经成功地使用 Google People API 来检索我的 Google 联系人,但我发现 API 到最后没有正确排序更新时间(例如使用 setSortOrder("LAST_MODIFIED_DESCENDING"))。更重要的是,在查看这段代码的输出时发现有一个有趣的模式:

  private static void getLastModified() throws GeneralSecurityException, IOException {
    PeopleService service = getService();
    ListConnectionsResponse response =
        service.people().connections().list("people/me")
        .setPageSize(30)
        .setPersonFields("names,metadata")
        .setSortOrder("LAST_MODIFIED_DESCENDING")
        .execute();
    for (Person person : response.getConnections()) {
      //System.out.println(person.getNames());
      for (Source s : person.getMetadata().getSources()) {
        if (s.getType().equals("CONTACT")) {
          System.out.println(s.getUpdateTime());
        }
      }
    }
  }

LAST_MODIFIED_DESCENDING 排序结果:

2020-05-07T19:27:27.469Z    <-- ok (which means this contact is for sure modified by me on the given day)
2020-05-07T19:27:03.418Z    <-- ok
2020-05-07T19:26:20.219Z    <-- ok
2020-05-07T19:25:39.684Z    <-- ok
2020-05-07T19:25:13.823Z    <-- ok
2020-05-07T19:24:13.732Z    <-- ok
2020-05-07T13:04:47.637Z    <-- ok
2020-04-12T17:18:31.714156Z <-- NOT ok (contact is probably modified by me on that day, but why is it positioned incorrectly?)
2020-04-15T20:49:28.733412Z <-- NOT ok
2020-05-06T17:20:19.840Z    <-- ok
2020-05-06T17:18:22.134Z    <-- ok
2020-05-06T17:17:33.185Z    <-- ok
2020-05-06T16:41:00.368Z    <-- ok
2020-05-06T16:40:50.119Z    <-- ok
2020-05-06T15:02:49.218Z    <-- ok
2020-05-06T14:29:27.963Z    <-- ok
2020-05-06T14:28:40.890Z    <-- ok
2020-05-06T14:26:56.322Z    <-- ok
2020-05-06T14:26:04.658Z    <-- ok
2020-05-06T14:25:17.177Z    <-- ok
2020-05-06T14:24:12.801Z    <-- ok
2020-05-06T14:23:13.461Z    <-- ok
2020-05-06T14:22:04.888Z    <-- ok
2020-04-12T19:26:25.392253Z <-- NOT ok
2020-05-06T12:05:32.209Z    <-- ok
2020-05-06T11:57:11.286Z    <-- ok
2018-08-15T13:49:04.254001Z <-- NOT ok
2020-04-12T15:10:27.421184Z <-- NOT ok
2020-05-05T17:51:52.572Z    <-- ok
2020-05-05T17:50:43.904Z    <-- ok

进一步分析后,似乎所有错位的联系人在其 metadata 结构(CONTACTPROFILE)中都有两种类型的 source 对象,其中只有CONTACT 包含 updateTime 时间戳,但 API 显然考虑了另一个帐户 - PROFILE 时间戳,通过 API 不可见。 换句话说,我列表中放错位置的联系人可能并没有放错位置,而是与原来的所有者发生了变化,但 API 没有显示第二个时间戳。

有人可以进一步阐明这一点并建议如何强制 API 忽略 PROFILE 元数据源并仅根据我的修改时间戳进行排序吗?

感谢@Raserhin 对 post 问题的建议Google 问题跟踪器 - 我做到了,得到了答案,我能够回答我自己的问题。

关于问题的第一部分:

Can someone shed some more light on this ...?

https://issuetracker.google.com/issues/156048409我得到了详细的解释,证明了我的猜测:

Our backend service does the sorting based on the last modified timestamp from both contacts and profiles contained in a given merged person. However when our People service passes through the data, it only exposes the timestamp from contacts, not from profiles. Yes, it is not an informative API design, when the sorting key fields are not fully returned. But I need to run the idea within the team and privacy review, if we want to expose the profile change timestamp.

问题的第二部分:

how to force API to ignore the PROFILE metadata source and sort only according to my modification timestamps?

API 目前显然无法做到这一点,因此每个需要使用此类排序的开发人员都必须考虑所描述的行为并选择接受它或创建解决方法(例如. 检索所有联系人并在不太昂贵的情况下对它们进行排序)。

今天,我们可以通过以下方式订购:

  • LAST_MODIFIED_ASCENDING : 按人物变化时间排序;年长的 首先输入。
  • LAST_MODIFIED_DESCENDING : 按时间排序 改变了;较新的条目优先。
  • FIRST_NAME_ASCENDING : 对人物进行排序 名字。
  • LAST_NAME_ASCENDING : 按姓氏排序。

来源:https://developers.google.com/people/api/rest/v1/people.connections/list#sortorder

This 是你要找的:

READ_SOURCE_TYPE_CONTACT Returns SourceType.CONTACT

这就是您问题的答案:“如何强制 API 忽略 PROFILE 元数据源并仅根据我的修改时间戳进行排序?