使用共享链接从 Office365 sharepoint graph api 获取文件

问题描述 投票:0回答:1

我有一堆来自我的组织的共享链接(

https://mycorp.sharepoint.com/:x/:y/<some_folder>/<sharing_id>

我发现自己无法使用此技术从图形 api 获取文件:

  • GET https://graph.microsoft.com/v1.0/sites/mycorp.sharepoint.com:/sites/<some_folder>
  • GET https://graph.microsoft.com/v1.0/sites/{site_id}/drives
  • GET https://graph.microsoft.com/v1.0/sites/{site_id}/drives/{drive_id}/root:/<sharing_id>/content

我有什么遗漏的吗?

sharepoint microsoft-graph-api office365
1个回答
0
投票

需要先展开分享链接见https://learn.microsoft.com/en-us/graph/api/shares-get?view=graph-rest-1.0&tabs=http

如果您使用 SDK,您需要首先对共享链接进行编码,然后您可以展开并从driveitem 获取下载网址,例如

string sharedlink = "https://xxxx-my.sharepoint.com/:w:/p/xxx/EXTw9StT51hKicApjyP3dQoBS2b8Z3FfaTv32Un5zeTbZA?e=ObtbwL";
string base64Value = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(sharedlink));
string encodedUrl = "u!" + base64Value.TrimEnd('=').Replace('/', '_').Replace('+', '-');
var sharedFile = graphclient.Shares[encodedUrl].DriveItem.GetAsync().Result;
var fileurl = sharedFile.AdditionalData["@microsoft.graph.downloadUrl"].ToString();

© www.soinside.com 2019 - 2024. All rights reserved.