r.t.s.
r.t.s.

Reputation: 585

OneDrive - Using Rest API to access a folder specified by a shared webURL

I am using the https://graph.microsoft.com/v1.0 endpoint and I obtain a shared link for a folder using: /drive/special/approot:{SomePath}:/createLink.

This returns a link that looks something like: https://1drv.ms/u/s!...pZqIns

Another user later will access the shared data using a browser with this URL. No Problem. But they also want to use my App which uses the rest API. How can I convert the link into a FileID so that they can use my App to access the folder and its contents?

If it matters ... this is not for the App Folder itself.

Upvotes: 0

Views: 1244

Answers (1)

Keen Jin
Keen Jin

Reputation: 1138

According to your description, I suppose you want to get a shared file by converting the shareLink.

Base on my test, when we create a shareLink for a file, we can get the shareLink for this file.

Then we can use the following steps to get the file information by converting the shareLink.

1.Encoding the shareLink by using the following logic:

  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.

As an example, to encode a URL in C#:

string sharingUrl = "{your shareLink}";
string base64Value = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(sharingUrl));
string encodedUrl = "u!" + base64Value.TrimEnd('=').Replace('/','_').Replace('+','-');

2.Using the folloing API to get the shared item:

GET /shares/{shareIdOrUrl}/driveItem

The 'shareIdOrUrl' parameter is the result in step1.

This API will return all the information about the shared file.

For more detail, we can refer to this document.

Upvotes: 1

Related Questions