![](/img/trans.png)
[英]Java - How to programmatically download an attachment from a URL which opens a new tab?
[英]How to get the download URL of an attachment of the MSTeam Chat?
我能夠使用以下測試版 API https://graph.microsoft.com/beta/teams/{group-id-for-teams}/channels/{channel-id}/messages獲取 MSTeam 聊天的附件信息/{message-id}/replies/{reply-message-id}
{
"@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
鏈接變成了直接下載鏈接!
我還沒有找到任何關於為什么這有效以及為什么有時一個結局有效而其他結局無效的信息,但到目前為止,至少一個結局適用於我測試過的所有文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.