Access publicly shared OneDrive folder via API

无人久伴 提交于 2019-12-01 10:38:16

Yes, you can use the REST API to access the contents of a folder.

The API is the one you mentioned, the shares API. However, it sounds like you are perhaps using the wrong ID.

The most straightforward way to do this is to follow the instructions to encode the actual sharing URL into a token. This way you create a base64 encoded version of the sharing link, append a "u!" to the front of that string, and then make the exact call you already mentioned. You'll get back a list of the files in the shared folder and you can go from there.

Here's an example of this: Here's a sharing link to a folder in OneDrive with some photos in it.

https://1drv.ms/f/s!AtuAM_NacwVahiFpuMGS_BiQCwWu

To convert this URL into the API, you first base64 encode the URL and append u!

u!aHR0cHM6Ly8xZHJ2Lm1zL2YvcyFBdHVBTV9OYWN3VmFoaUZwdU1HU19CaVFDd1d1

Now you can use this URL as the sharing token, and expand children and thumbnails:

https://api.onedrive.com/v1.0/shares/u!aHR0cHM6Ly8xZHJ2Lm1zL2YvcyFBdHVBTV9OYWN3VmFoaUZwdU1HU19CaVFDd1d1/root?expand=children

Clicking on this bottom link should give you the JSON response, which includes the shared folder and the children inside the folder.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!