简体   繁体   English

如何从OneDrive API获取共享和下载链接

[英]How can I get share and download links from OneDrive API

I am using the OneDrive JS Picker and would like to get both a download and share value. 我正在使用OneDrive JS Picker,并希望获得下载和共享的价值。 The sample in the documentation lists the options for the action parameter separated by pipes. 文档中的示例列出了用管道分隔的action参数的选项。 I was hoping to use bitwise operators to combine those values (eg 我希望使用按位运算符来合并这些值(例如

action: "share | download"

but that doesn't seem to allow both the webUrl value and the download url (@microsoft.graph.downloadUrl)... has anybody else been able to do this? 但这似乎既不允许webUrl值也不允许下载URL(@ microsoft.graph.downloadUrl)...其他人是否能够做到这一点? Or is there a way to use the share URL (webUrl) to get a download url so we can get the text contents of files? 还是有一种方法可以使用共享URL(webUrl)获取下载URL,以便我们可以获取文件的文本内容?

I know there is a REST service available though that may be deprecated, given the message at the top of that page: 我知道有REST服务可用,但鉴于该页面顶部的消息,该服务可能已被弃用:

This documentation is archived and is not being maintained. 本文档已存档,不再维护。

but if that is still usable, perhaps we could use that to download the file... if so, can I put the file id in that download URL and an access token? 但是如果仍然可以使用,也许我们可以用它来下载文件...如果可以,我可以将文件ID放在该下载URL和访问令牌中吗?

I was able to host the OneDrive.js file locally, un-minify it and modify the line below (line 104) to have the downloadUrl included in all queries on files. 我能够在本地托管OneDrive.js文件 ,取消最小化并修改下面的行(第104行)以使downloadUrl包含在文件的所有查询中。 That allows us to get a shareUrl and a downloadUrl. 这样就可以获取shareUrl和downloadUrl。

e.DEFAULT_QUERY_ITEM_PARAMETER = "expand=thumbnails&select=id,name,size,webUrl,folder,@content.downloadUrl";

sorry for the missleading pipe sign. 对不起,误导了管道标志。 Actually right now we only allow one action per request like (action: "query"). 实际上,目前我们每个请求只允许执行一个操作,例如(操作:“查询”)。 The pipeline sign in the doc means 'or' in English not in code. doc中的管道符号用英语而不是代码表示“或”。

Before my answer, I want to clarify the difference between a webUrl and a shareUrl. 在回答之前,我想澄清一下webUrl和shareUrl之间的区别。

  • A webUrl which you see in the response's 'webUrl' attribute is the url pointed to the resource online which requires user login to see it. 您在响应的“ webUrl”属性中看到的webUrl是指向资源在线的url,需要用户登录才能看到它。

  • A shareUrl which contains the permission which everyone who has the link could see/edit it based on the user's config. 一个shareUrl包含许可,拥有该链接的每个人都可以根据用户的配置查看/编辑该许可。

JS Picker JS Picker

If you want the download link and a webUrl back at the same time, it should be easy: 如果您希望同时返回下载链接和webUrl,则应该很容易:

{
    action: "query",
    advanced: {queryParameters: "select=id,name,webUrl,@content.downloadUrl"}
}

If you want both the download link and share link back at the same time, it is not supported. 如果要同时返回下载链接和共享链接,则不支持。

API API

For using the API to achieve this, you can go to the new API page: https://dev.onedrive.com/items/get.htm 为了使用API​​实现此目的,您可以转到新的API页面: https : //dev.onedrive.com/items/get.htm

and get the item with already shared links should be 并获得已共享链接的项目应为

GET /v1.0/drive/items/<item-id>?select=id,name,@content.downloadUrl,webUrl&expand=permissions

all already shared links should be returned in the permissions array object. 所有已经共享的链接都应在权限数组对象中返回。

If you don't have a shared link, and you need to create the shared link, you should try https://dev.onedrive.com/items/sharing_createLink.htm 如果没有共享链接,并且需要创建共享链接,则应尝试https://dev.onedrive.com/items/sharing_createLink.htm

while it does not return the webUrl and download url back so you need an extra request. 虽然它不返回webUrl并下载回URL,所以您需要额外的请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM