Onedrive API 在给定 Link 上读取文件

Onedrive API read files on given Link

我想使用 Microsoft Cognitive Services 和 Onedrive 创建项目 API。

场景是:用户将给我一个 Onedrive link,我的 API 将把文件放在该文件夹中。

可能吗?

如果是这样,我在哪里可以找到更多关于它的文档?

您需要使用 shares API 使用编码版本的 OneDrive Link。

GET ../v1.0/shares/{sharingTokenOrUrl}

在您的例子中,sharingTokenOrUrl 是按以下方式编码的 URL:

  1. 首先,使用base64编码URL.
  2. 将base64编码结果转换为未填充的base64url格式 从值的末尾删除 = 字符,将 / 替换为 _ 和 + 与 -.)
  3. 追加你!成为字符串的开头。

例如,要在 C# 中对 URL 进行编码:

string sharingUrl = "https://onedrive.live.com/redir?resid=1231244193912!12&authKey=1201919!12921!1";
string base64Value = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(sharingUrl));
string encodedUrl = "u!" + base64Value.TrimEnd('=').Replace('/','_').Replace('+','-');

查看 this documentation 以获得 shares 端点的完整描述。