Microsoft Graph如何获取共享文件?
How to get the shared file with Microsoft Graph?
我想通过 MS graph API 将文件从 MS OneDrive 共享给用户。用户可以直接通过 link 查看我的共享文件。我已阅读为 DriveItem 创建共享 Link 的文档,并使用此 API 为我的共享文件创建共享 link。
请问MS Graph如何实现API?欢迎任何建议和提示。谢谢
根据你的描述,我假设你想通过 MS Graph 获取共享文件 API。
根据我的测试,我们可以为这个文件创建一个shareLink。
然后我们可以通过以下步骤,通过转换shareLink获取文件信息
使用以下逻辑对 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.
- 如果要访问共享文件,可以使用以下API:
GET /shares/{shareIdOrUrl}/driveItem
shareIdOrUrl
参数就是step1的结果。
这API将return有关共享文件的所有信息。
例如,要在 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.
我想通过 MS graph API 将文件从 MS OneDrive 共享给用户。用户可以直接通过 link 查看我的共享文件。我已阅读为 DriveItem 创建共享 Link 的文档,并使用此 API 为我的共享文件创建共享 link。
请问MS Graph如何实现API?欢迎任何建议和提示。谢谢
根据你的描述,我假设你想通过 MS Graph 获取共享文件 API。
根据我的测试,我们可以为这个文件创建一个shareLink。
然后我们可以通过以下步骤,通过转换shareLink获取文件信息
使用以下逻辑对 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.
- 如果要访问共享文件,可以使用以下API:
GET /shares/{shareIdOrUrl}/driveItem
shareIdOrUrl
参数就是step1的结果。
这API将return有关共享文件的所有信息。
例如,要在 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.