项目地址:
https://github.com/weiyidu/OneDrive
1.支持文件夹上传.
2.支持获取文件的匿名直链.
3.纯shell支持.
安装步骤:
1 |
wget --no-check-certificate -q -O /tmp/OneDrive.sh "https://raw.githubusercontent.com/weiyidu/OneDrive/master/OneDrive.sh" && chmod +x /tmp/OneDrive.sh && bash /tmp/OneDrive.sh |
注:脚本中已经配置默认export api_ 三个参数,不需要自己获取,可以直接运行账号认证程序操作。(2019.11.16更新)
修改配置文件 /usr/local/etc/OneDrive/onedrive.cfg
export api_client_id=""
export api_client_secret=""
export api_reply_url="https://onedrive.live.com/about/business/"
下面讲解如何获取这三个参数
首页进入Microsoft Azure Management Portal(https://manage.windowsazure.com/)
1、点击左侧菜单栏中的Azure Active Directorg,选择应用注册,点击页面上方的 新应用程序注册
2、输入名称 如:OneDrive for Linux
应用程序类型选择Web应用/API
填入登陆URL:
https://login.microsoftonline.com/
3、点击“创建”后自动跳转应用信息页面,点击左上角的设置,点击右边的回复URL,将其修改为:https://onedrive.live.com/about/business/
4、点击 所需权限,点击Windows Azure Active Directory确认是否已选中Sign in and user profile,如果没有则选中并点击完成。
5、点击上方的添加,选择API
选中Office 365 SharePoint Online,并点击选择
在委派权限中选中 Read user files 和 Read and write user files
6、点击密钥,填入密钥描述,如:OneDrive ,选择年限,然后保存。
注:建议把密钥复制保存在本地
教程到此已经把上面所需的三个参数全部获取到。
当以上步骤全部完成,你需要运行账号认证程序:
1、运行onedrive -a
2、将上图返回的网址复制到浏览器中打开
3、登陆你的OneDrive for Business账号
4、登陆成功后复制地址栏中的地址,并提取code的字段(code=后面至&前面)
5、粘贴至终端,并敲回车键
如果返回错误信息,请检查code字段,或重新生成密钥
更新:2018.07.16
疑为原版项目地址:
https://github.com/fkalis/bash-onedrive-upload
看了一下onedrive.cfg代码是一样的,应该Vicer大佬根据原版重写的。
关于更改上传目录
修改onedrive.cfg配置文件,默认是使用export api_root_folder="root",直接传到网盘根目录。
修改为自定义文件夹上传是有问题的,但是修改为官方给的文件夹是可以上传的,详细使用到原项目中查看。
1 |
export api_root_folder="special/documents" |
在网盘显示为“文档”,注:documents后面不能再添加文件夹
更新:2018.08.12
1 |
{"error":"invalid_client","error_description":"AADSTS70002: Error validating credentials. AADSTS50012: Invalid client secret is provided.\r\nTrace ID: 974f5bed-cf75-4cf6-84e3-04b554752900\r\nCorrelation ID: 38c7eee1-3c34-4684-94a1-af3cfadc71be\r\nTimestamp: 2018-08-12 09:41:29Z","error_codes":[70002,50012],"timestamp":"2018-08-12 09:41:29Z","trace_id":"974f5bed-cf75-4cf6-84e3-04b554752900","correlation_id":"38c7eee1-3c34-4684-94a1-af3cfadc71be"} |
报错原因:在生成的密钥串中含有“+”号,在浏览器会把“+”编码成%2B<可以在百度搜索“1+2”,看一下URL地址栏就懂了>
解决办法:1、生成一个不带“+”号的密钥串(建议);2、编码符号,把“+”变为%2B
更新:2018.08.20
经测试使用新建应用的ID和secret会出错,可以使用我的配置。
api_client_id="aef2b3c3-6be5-412c-88a0-e320a480daa8"
api_client_secret="w0SlTCJdZhxvazktBb9MLO7rNyozpMJlFj8YTbDkuoA="
api_reply_url="https://onedrive.live.com/about/business/"
文章参考:moeclub.org
文章评论
大佬你好,麻烦问下,所有的都配置好了,It seems like we have a refresh token, so we are ready to go了。
但上传文件时提示:An error has occurred while uploading XXXX(文件名) (Code: 000),能帮忙分析下可能是哪里错了吗?谢谢!
@Simen 前两我在使用命令上传也出这个问题,写教程的时候却没有。
https://www.234du.com/1171.html,现在配合这个自动上传脚本还没发现有问题
@六度 我也是,直接onedrive 命令上传文件没问题,-f上传文件夹就出现这个错误
@六度 好像要用onedrive-d 一个文件夹
中间没有空格
@anadano 我是用来配合Aria2下载后自动上传OneDriver,并没使用命令操作,https://github.com/0oVicero0/OneDrive这是原作者,作者更新了源代码。
@六度 哦哦,谢大佬啦
单独使用-f指令提示:
root@VM-0-12-debian:~# onedrive -f /home/233.txt
Could not create folder '' in ''
使用-d的debug模式提示
root@VM-0-12-debian:~# onedrive -d /home/233.txt
2018-08-15 20:52:39 Size of 233.txt is less than or equal to 104857600 bytes, will use simple upload
2018-08-15 20:52:39 Uploading '/home/233.txt' as '233.txt' into root folder (root)
2018-08-15 20:52:39 Retrying full upload of '/home/233.txt' (Previous code: 000)
2018-08-15 20:52:39 Size of 233.txt is less than or equal to 104857600 bytes, will use simple upload
2018-08-15 20:52:40 Uploading '/home/233.txt' as '233.txt' into root folder (root)
2018-08-15 20:52:40 Retrying full upload of '/home/233.txt' (Previous code: 000)
2018-08-15 20:52:40 Size of 233.txt is less than or equal to 104857600 bytes, will use simple upload
2018-08-15 20:52:40 Uploading '/home/233.txt' as '233.txt' into root folder (root)
An error has occurred while uploading '/home/233.txt' (Code: 000)
root@VM-0-12-debian:~# onedrive -d -f /home/233.txt
2018-08-15 20:52:47 Searching for '' in ''
2018-08-15 20:52:47 Creating folder '' in ''
Could not create folder '' in ''
认证明明已经成功,却总是在上传时出错,为什么?
@YBurger 这个问题很奇怪,上周查了两天没找到原因。可以先看看这篇文章https://www.234du.com/1171.html
@六度 经测试应该是Microsoft Azure Management Portal创建的应用的问题,我使用我自己创建的应用就会出现这种问题,不过使用萌咖博主(moeclub)的client id和secret进行认证就可以正常使用,原因不明。我还专门按照博主你文中的步骤和萌咖博主文章中的步骤一步步重新创建应用,上传时却依然失败,不知是否微软对后创建的应用做出了限制。
@YBurger 同一样的问题