通过API访问公开共享的OneDrive文件夹 [英] Access publicly shared OneDrive folder via API

查看:433
本文介绍了通过API访问公开共享的OneDrive文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个公共共享的OneDrive文件夹,其中包含一些子文件夹和文件. IE.我已经通过链接共享了它,因此具有此链接的任何人都可以访问它们.

I have a publicly shared OneDrive folder with some various sub-folders and files. I.e. I have shared it via a link, so anyone with this link can access them.

是否可以通过某种REST API从客户端JavaScript或某些服务器端代码访问这些文件?无需使用任何特定于用户的凭据?

Is there a way I can access these files from either client-side JavaScript or some server-side code via a REST API of some sort? Without having to use any sort of user-specific credentials?

我一直在尝试的事情

我一直在查看访问共享内容页,喜欢我想要的东西,但不知道如何使用它.

I've been looking at the Accessing Shared Content page, and it looks like what I want, but can't figure out how to use it.

我从共享URL中获取了一个看起来像ID的东西,它看起来像是一个长十六进制数字(似乎是一个指向我的ID?),一个!,然后是一个数字(我认为是与共享资源有关.

I've taken something that looks like an id from the shared URL, which looks to be a long hexadecimal number (which seems to be an id pointing at me?), an !, and then a number (which I assume has to do with the shared resource).

然后我尝试将其粘贴在此URL中:

I've then tried to stick it in this URL:

https://api.onedrive.com/v1.0/shares/<id>/root?expand=children

但是我又收到了400错误的请求,所以有些不对劲...

But I get back a 400 Bad Request, so something isn't quite right...

我正在考虑可能缺少某种身份验证,但是由于共享文件是公共的,因此我不需要用户使用其凭据登录,当然也不能在代码中使用我自己的凭据.

I'm thinking maybe some sort of authentication is missing, but since the shared files are public, I don't users to have to login with their credentials, and can't of course use my own in code.

我已经尝试注册一个应用,在此我会获得一个应用ID(GUID),可以生成密码和密钥对.希望我可以使用它,但是在API中看不到如何实际使用这些位置以及在哪里使用...

I've tried to register an app, where I get an application id (guid) and can generate Passwords and Key-Pairs. Was hoping maybe I could use that, but don't see in the API how and where to actually use those...

目标

共享文件夹包含合唱团的活页乐谱,我负责保持合唱团的更新(这里OneDrive同步非常方便).

The shared folder contains sheet music for a choir, that I'm responsible for keeping updated (and OneDrive syncing is super handy here).

某些成员不是很精通计算机,所以我希望尽可能轻松地查看和下载这些文件.共享链接带有转到此 other 奇怪的网站并在此处找到文件"的文本工作方式,但是我更想直接在的仅限会员"区域列出文件我们的网站.基本上只是这里有文件,请单击其中一个进行下载".

Some members aren't very computer savvy, so I'd like to make seeing and downloading these files as easy as possible. The shared link with a "go here to this other strange site and find the files there"-text sort of works, but I would much rather like to list the files directly in a member-only area of our website. Basically just "here are the files, click on one to download it".

推荐答案

是的,您可以使用REST API访问文件夹的内容.

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

您所提到的API是 shares API.但是,听起来您可能使用了错误的ID.

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

最简单的方法是按照说明进行操作编码将实际的共享URL转换为令牌.通过这种方式,您可以创建共享链接的base64编码版本,并添加"u!".到该字符串的开头,然后进行您已经提到的确切调用.您将获得共享文件夹中文件的列表,然后可以从那里访问.

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.

这是一个例子: 这是指向OneDrive中包含照片的文件夹的共享链接.

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

要将此URL转换为API,首先需要对URL进行base64编码,然后附加u!

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

u!aHR0cHM6Ly8xZHJ2Lm1zL2YvcyFBdHVBTV9OYWN3VmFoaUZwdU1HU19CaVFDd1d1

u!aHR0cHM6Ly8xZHJ2Lm1zL2YvcyFBdHVBTV9OYWN3VmFoaUZwdU1HU19CaVFDd1d1

现在,您可以将该URL用作共享令牌,并展开子代和缩略图:

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

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

单击此底部链接应为您提供JSON响应,其中包括共享文件夹和该文件夹中的子项.

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

这篇关于通过API访问公开共享的OneDrive文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆