download - 如何获取 MSTeam 聊天附件的下载 URL?
问题描述
{
"@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}
这使
{
"@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",
"name": "MsteamchatHistory Documentation.docx",
"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,
.....
}
在这里,我通过探索组找到了 item-id。但我想从相应的附件 ID 中找到项目 ID,以便我可以获取该附件的下载 URL,并使用它使用 HttpWebRequest 进行下载。
那么,是否可以从附件 ID 中获取驱动器项目 ID?如果是,怎么做?
提前致谢。
解决方案
我的一个客户最近问过我这个问题,我实际上找到了一个快捷方式来为 SharePoint 文件创建下载链接。由于您的团队附件存储在 SharePoint 文件夹中(根据 URL),您应该也可以使用此技巧。
使用内容 URL,将&download=1
, ?download=1
, 或添加?Web=0
到 URL 的末尾,如下所示:
https://.......1/Shared Documents/General/MsteamchatHistory Documentation.docx?download=1
并且链接变成了直接下载链接!
我还没有找到任何信息说明为什么会这样以及为什么有时一个结局会起作用而其他结局不会,但到目前为止,至少一个结局对我测试过的所有文件都有效。
推荐阅读
- flutter - Flutter DataTable 的默认线型是什么?
- amazon-web-services - 我如何确保我的 aws s3 存储桶只能写入
- php - WooCommerce 自定义 PHP 代码以更改“添加到购物车”按钮文本
- wifi - ESP32 为什么深度睡眠后 WiFi 连接会导致“触发掉电检测器”
- javascript - 页面加载时出错,而不是表单提交后?
- python - 通过掩码选择numpy数组的元素并保留原始尺寸
- php - 警告:file_get_contents():php_network_getaddresses:getaddrinfo 失败:名称无法解析
- haskell - 关于列表及其声明的问题(haskell)
- python - 为什么 Pymesh 布尔运算在我简单的几何设置中非常慢?
- excel - VBa 和 Excel - 使用变体过滤表格