【问题标题】:Is there a way to query and filter the Google People API connections through contact group id?有没有办法通过联系人组 id 查询和过滤 Google People API 连接?
【发布时间】:2021-02-13 01:43:35
【问题描述】:

我正在使用 Google People API 来填充我的仪表板的地址簿。我有很多联系人,所以我的想法是通过为此服务创建特定组来过滤联系人。我需要的基本上是查询在特定组 id 上过滤的所有连接的可能性。似乎官方API只有“列表”方法,没有机会查询。我正在使用 node.js 的客户端库,这是我的代码:

const {google} = require('googleapis');

const getGoogleConnections = async (userToken) => {
  const oauth2Client = new google.auth.OAuth2;
  oauth2Client.setCredentials({
    'access_token': userToken, //Passport session user
  });

  const googlePeople = await google.people({
    version: 'v1',
    auth: oauth2Client,
  });

  const params = {
    resourceName: 'people/me',
    pageSize: 200,
    sortOrder: 'LAST_MODIFIED_DESCENDING',
    personFields: ['names', 'emailAddresses', 'memberships', 'organizations'],
  };

  const connections = await googlePeople.people.connections.list(params);
  return connections;
};

我的回答:

"connections": [
            {
                ... //returning all specified personFieldsValues 
                "memberships": [
                    {
                        "metadata": {
                            "source": {
                                "type": "CONTACT",
                                "id": "id value"
                            }
                        },
                        "contactGroupMembership": {
                            "contactGroupId": "contact group id",
                            "contactGroupResourceName": "contactGroups/contact group id"
                        }
                    },
                    {
                        "metadata": {
                            "source": {
                                "type": "CONTACT",
                                "id": "metadata id "
                            }
                        },
                        "contactGroupMembership": {
                            "contactGroupId": "myContacts",
                            "contactGroupResourceName": "contactGroups/myContacts"
                        }
                    }
                ]
            }
        ],

我的响应是正确的,API 会返回所有值,但我无法找到一种方法来过滤联系人组 ID 上的这些返回值。以前有人试过吗?

【问题讨论】:

  • 不幸的是,在现阶段,People API中似乎没有直接过滤“people.connections”的“group id”返回值的方法。因此,作为当前的解决方法,如何在检索值后通过脚本过滤值。但我不确定这是否与您期望的方向相同。所以我提出了这个作为评论。
  • 从端点加载多个资源需要时间,所以这可能是一个想法,但我会等到他们提出过滤方法
  • 感谢您的回复。在这种情况下,如何将其发布为当前解决方法的答案?通过这个,我认为它对其他有同样问题的用户很有用。

标签: node.js api google-api-nodejs-client google-people-api


【解决方案1】:

问题:

正如 cmets by Tanaike 中所述,在调用 people.connections.list 时无法过滤返回的连接(没有可选的查询参数或类似参数,这与来自 Google API 的其他 list 方法不同)。

提交功能请求:

如果您认为此功能可能有用,我建议您在问题跟踪器的People component 上提出此请求。

解决方法:

同时,您可以在 API 返回连接后过滤连接。您可以使用filtersome 按照以下方式根据组ID 过滤它们:

const connections = await googlePeople.people.connections.list(params); 
const filteredConnections = connections.connections.filter(connection => {
  return connection.memberships.some(membership => {
    if (membership.contactGroupMembership) {
      return membership.contactGroupMembership.contactGroupId === "YOUR_GROUP_ID";
    } else return false;
  });
});

【讨论】:

  • 使用 C# 代码过滤,而不是 Gmail 之类的表达式?
  • @Kiquenet 我不确定你对not expressions like Gmail 的意思。也许您可以考虑发布一个新问题?
  • 您可以在 Gmail 中使用的搜索运算符:support.google.com/mail/answer/7190?hl=en
  • @Kiquenet 这与当前问题和 People API 有什么关系?
  • 现在有这个功能吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多