【问题标题】:How to get the shared file with Microsoft Graph?如何获取 Microsoft Graph 的共享文件?
【发布时间】:2018-09-18 02:22:20
【问题描述】:

我想通过 MS 图形 API 将文件从 MS OneDrive 共享给用户。用户可以直接通过链接查看我的共享文件。我已阅读为 DriveItem 创建共享链接的文档并使用此 API 为我的共享文件创建共享链接。

我想知道如何使用 MS 图形 API 来实现?欢迎任何建议和提示。谢谢

【问题讨论】:

    标签: microsoft-graph-api onedrive


    【解决方案1】:

    根据您的描述,我假设您希望使用 MS Graph API 获取共享文件。

    根据我的测试,我们可以为这个文件创建一个shareLink。

    那么我们就可以使用下面的步骤,通过转换shareLink来获取文件信息。

    1. 使用以下逻辑对 shareLink 进行编码:

              1)First, use base64 encode the URL.
              2)Convert the base64 encoded result to unpadded base64url format by removing = characters from the end of the value, replacing / with _ and + with -.)
              3)Append u! to be beginning of the string.
      
    2. 如果要访问共享文件,可以使用以下 API:

    GET /shares/{shareIdOrUrl}/driveItem

    shareIdOrUrl 参数是 step1 中的结果。

    此 API 将返回有关共享文件的所有信息。

    例如,在 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 document.

    【讨论】:

    • 非常感谢,对我很有帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多