【问题标题】:Retrieving file item ID from teams message attachment ID从团队消息附件 ID 中检索文件项 ID
【发布时间】:2020-08-18 02:40:11
【问题描述】:

使用 Microsoft 图形 API,我会收到每条 MS Teams 消息的 webhook 通知。当收到以下格式的带有文件附件的消息时:

"attachments": [
    {
        "id": "aa567f71-4702-4b43-b756-2f453ddb662a",
        "contentType": "reference",
        "contentUrl": "... the url",
        "content": null,
        "name": "my file.xlsm",
        "thumbnailUrl": null
    }
],

然后我尝试调用图形 API 以检索文件信息并使用上面的 id (https://graph.microsoft.com/v1.0/groups/" + teamId + "/drive/items/" + id) 对其执行操作(特别是删除)并获取错误(找不到资源)。我猜我在附件中获得的 id 不是文件项 ID。有没有办法使用图形 API 从附件 ID 中获取项目 ID?

【问题讨论】:

标签: microsoft-graph-api microsoft-teams sharepoint-api


【解决方案1】:

我们在附件响应中收到的ID实际上是etag id,除了直接下载内容,我们根本无法使用它。

可能有两种方法可以检索文件元数据信息。

  1. 搜索标签 作为您收到的资源数据的一部分,您将收到团队或用户 ID。您可以将请求 url 创建为: /groups/<team-id>/drive/root/delta?search(q='<attachment-name>')

上述查询并不可靠,根据 MS 索引它的速度可能需要 2-5 分钟。

  1. 过滤标签 我目前使用的另一种方法是使用“filesFolder”查询获取文件夹 ID,然后使用过滤器 odata 标签获取文件元数据。

示例:/teams/<team-id>/channels/<channel-id>/filesFolder?$select=id

使用上面的 id,我们可以做以下事情。 /groups/<team-id>/drive/item/folder-id/children?filter=name eq 'attachment_name'

【讨论】:

    猜你喜欢
    • 2021-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-07
    • 1970-01-01
    相关资源
    最近更新 更多