如何获取MSTeam聊天附件的下载URL?

问题描述

我可以使用以下测试版API获取MSTeam聊天的附件信息 https://graph.microsoft.com/beta/teams/{group-id-for-teams}/channels/{channel-id}/messages/{message-id}/replies/{reply-message-id}

例如https://graph.microsoft.com/beta/teams/e7884ec9-cbf3-4661-b74a-6fc42ac34ce1/channels/19:6a04c17090e249319b3731cbe72e6085@thread.tacv2/messages/1600060770982/replies/1600061187436

{
    "@odata.context": "https://graph.microsoft.com/beta/$Metadata#teams('e7884ec9-cbf3-4661-b74a-6fc42ac34ce1')/channels('19%3A6a04c17090e249319b3731cbe72e6085%40thread.tacv2')/messages('1600060770982')/replies/$entity","id": "1600061187436","replyToId": "1600060770982","etag": "1600061187436",.....
    "attachments": [
        {
            "id": "40ce4e84-6e47-43ed-acb9-9edcddff5ef4","contentType": "reference","contentUrl": "https://.......1/Shared Documents/General/MsteamchatHistory Documentation.docx","content": null,"name": "MsteamchatHistory Documentation.docx","thumbnailUrl": null
        }
    ],......
}

无法使用ContentUrl下载,因此找到了获取downloadURL的方法,以便可以使用HttpWebRequest进行下载。

获取下载URL的一种方法是使用 https://graph.microsoft.com/v1.0/groups/{group-id-for-teams}/drive/items/{item-id}

例如https://graph.microsoft.com/v1.0/groups/e7884ec9-cbf3-4661-b74a-6fc42ac34ce1/drive/items/012PWSBOUEJ3HEAR3O5VB2ZOM63TO76XXU

给出

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$Metadata#groups('e7884ec9-cbf3-4661-b74a-6fc42ac34ce1')/drive/items/$entity","@microsoft.graph.downloadUrl": "https://nepa1.sharepoint.com/sites/Venio1/_layouts/15/download.aspx?UniqueId=40ce....0&ApiVersion=2.0","createdDateTime": "2020-09-14T05:26:14Z","eTag": "\"{40CE4E84-6E47-43ED-ACB9-9EDCDDFF5EF4},2\"","id": "012PWSBOUEJ3HEAR3O5VB2ZOM63TO76XXU","lastModifiedDateTime": "2020-09-14T05:26:21Z","webUrl": "https://nepa1.sharepoint.com/sites/Venio1/_layouts/15/Doc.aspx?sourcedoc=%7B40CE4E84-6E47-43ED-ACB9-9EDCDDFF5EF4%7D&file=MsteamchatHistory%20Documentation.docx&action=default&mobileredirect=true","cTag": "\"c:{40CE4E84-6E47-43ED-ACB9-9EDCDDFF5EF4},3\"","size": 563211,.....
}

在这里,我通过探索群组找到了商品ID。但是我想从相应的附件ID中找到项目ID,以便获得该附件的下载URL,并使用它通过HttpWebRequest进行下载。

那么,是否可以从附件ID中获取驱动器项目ID?如果是,该怎么办?

谢谢。

解决方法

我的一位客户最近问我这个问题,实际上我找到了为SharePoint文件建立下载链接的快捷方式。由于您的团队附件存储在SharePoint文件夹中(根据URL),因此您也应该能够使用此技巧。

使用内容URL,将build job: 'B',parameters:[booleanParam(name: 'TEST',value:'true')],wait: true &download=1?download=1添加到URL的末尾,如下所示:

?Web=0

该链接变成直接下载链接!

我还没有找到任何有关此功能为什么起作用的信息,以及为什么有时一个结尾会起作用而其他结尾却不起作用的信息,但是到目前为止,至少一个结尾对我测试过的所有文件都起作用。