使用 Microsoft Graph 创建永久 public 下载 link 到 OneDrive 文件
Create a permanent public download link to OneDrive file using Microsoft Graph
我正在尝试使用 Microsoft Graph API 永久 public 下载 link 到 OneDrive 文件。目标是 <img src="DOWNLOAD_LINK">
在我的网站上,并且 OneDrive 图像文件适用于查看该页面的任何用户。
目前我尝试了以下方法:
GET https://graph.microsoft.com/beta/me/drive/root:/PATH/TO/FILE.png
(doc) 其中 returns
@microsoft.graph.downloadUrl
: Public 下载 link 但 1 小时后过期。
webUrl
: 私人下载 link,需要身份验证。
.
POST https://graph.microsoft.com/beta/me/drive/root:/PATH/TO/FILE.png:/createLink
(doc) 与 JSON body
{
"type": "view",
"scope": "anonymous"
}
哪个returns
link.webUrl
: Public link 但不是下载 link。它而是在 OneDrive 文件查看器中打开文件(然后我无法在 HTML 中 use/embed)。
.
使用之前的 link.webUrl
生成下载 url (doc):
$linkWebUrl = "https://domain-my.sharepoint.com/:i:/g/personal/username_domain/RANDOMTOKEN";
$b64 = base64_encode($linkWebUrl);
$b64 = trim($b64, "=");
$b64 = str_replace("/", "_", $b64);
$b64 = str_replace("+", "-", $b64);
$url = "https://api.onedrive.com/v1.0/shares/u!" . $b64 . "/root/content";
但是 returns
{"error":{"code":"invalidRequest","message":"Invalid shares key."}}
我认为这是因为我将 Graph 和 OneDrive APIs 混合在一起,所以它无法识别密钥?将 api.onedrive.com
替换为 graph.microsoft.com
也不起作用,因为 Graph 需要通常的授权 header.
有人知道有用的东西吗?
您非常接近,但需要将 download=1
url 查询参数附加到生成的共享 link 以创建 下载 link,例如:
https://{tenant}-my.sharepoint.com/:i:/g/personal/{account-name}_onmicrosoft_com/{token}?download=1
就是这样。
Just a side note regarding the the error which occurs in step 3.
A sharing link generated for OneDrive for Business or SharePoint
(https://tenant-my.sharepoint.com) could not be utilized via OneDrive
Personal (https://api.onedrive.com) shares
endpoint
我正在尝试使用 Microsoft Graph API 永久 public 下载 link 到 OneDrive 文件。目标是 <img src="DOWNLOAD_LINK">
在我的网站上,并且 OneDrive 图像文件适用于查看该页面的任何用户。
目前我尝试了以下方法:
GET https://graph.microsoft.com/beta/me/drive/root:/PATH/TO/FILE.png
(doc) 其中 returns@microsoft.graph.downloadUrl
: Public 下载 link 但 1 小时后过期。webUrl
: 私人下载 link,需要身份验证。
.
POST https://graph.microsoft.com/beta/me/drive/root:/PATH/TO/FILE.png:/createLink
(doc) 与 JSON body
{
"type": "view",
"scope": "anonymous"
}
哪个returns
link.webUrl
: Public link 但不是下载 link。它而是在 OneDrive 文件查看器中打开文件(然后我无法在 HTML 中 use/embed)。
.
使用之前的
link.webUrl
生成下载 url (doc):
$linkWebUrl = "https://domain-my.sharepoint.com/:i:/g/personal/username_domain/RANDOMTOKEN";
$b64 = base64_encode($linkWebUrl);
$b64 = trim($b64, "=");
$b64 = str_replace("/", "_", $b64);
$b64 = str_replace("+", "-", $b64);
$url = "https://api.onedrive.com/v1.0/shares/u!" . $b64 . "/root/content";
但是 returns
{"error":{"code":"invalidRequest","message":"Invalid shares key."}}
我认为这是因为我将 Graph 和 OneDrive APIs 混合在一起,所以它无法识别密钥?将 api.onedrive.com
替换为 graph.microsoft.com
也不起作用,因为 Graph 需要通常的授权 header.
有人知道有用的东西吗?
您非常接近,但需要将 download=1
url 查询参数附加到生成的共享 link 以创建 下载 link,例如:
https://{tenant}-my.sharepoint.com/:i:/g/personal/{account-name}_onmicrosoft_com/{token}?download=1
就是这样。
Just a side note regarding the the error which occurs in step 3.
A sharing link generated for OneDrive for Business or SharePoint (https://tenant-my.sharepoint.com) could not be utilized via OneDrive Personal (https://api.onedrive.com)
shares
endpoint