系统环境:
CentOS7 + Python 2.7
安装软件工具:
pip install requests
pip install bypy
授权登陆:
执行 bypy info,显示下边信息,根据提示,通过浏览器访问下边灰色的https链接,如果此时百度网盘账号正在登陆,会出现长串授权码,复制。
[root@localhost ~]# bypy info
Please visit: # 访问下边这个连接,复制授权码
https://openapi.baidu.com/oauth/2.0/authorize?scope=basic+netdisk&redirect_uri=oob&response_type=code&client_id=q8WE4EpCsau1oS0MplgMKNBn845c39907e704f38dfebd29be380b80f
And authorize this app
Paste the Authorization Code here within 10 minutes.
Press [Enter] when you are done # 提示在下边粘贴授权码
用浏览器打开上面的链接
输入授权码
Press [Enter] when you are done
845c39907e704f38dfebd29be380b80f
Authorizing, please be patient, it may take upto None seconds...
Authorizing/refreshing with the OpenShift server ...
OpenShift server failed, authorizing/refreshing with the Heroku server ...
Successfully authorized
Quota: 2.020TB
Used: 1.215TB
授权成功
测试上传和同步本地文件到云盘
由于百度PCS API权限限制,程序只能存取百度云端/apps/bypy目录下面的文件和目录。我们可以通过:
[root@localhost ~]# bypy list
/apps/bypy ($t $f $s $m $d):
bypy常用命令
bypy list 查看目录
bypy mkdir 新建目录
bypy upload 把本地当前目录下的文件同步到百度云盘
bypy downdir 把云盘上的内容同步到本地
bypy list 显示文档
bypy upload filename 上传文档
bypy downdir filename 下载文件(存在问题)
bypy compare 比较本地当前目录和云盘(程序的)根目录
bypy -c 取消令牌文件。一段时间后要重新授权
命令:bypy upload localfile cloudfile
说明:1) localfile为本地文件路径
2)cloudfile为云端文件路径
3)由于百度的限制,最终文件只能上传到云盘,我的应用程序(apps) /bypy下
例: bypy upload /root/Outline-Manager.exe
显示上传进度,可使用命令:bypy -v upload localfile cloudfile
例:bypy -v upload /root/Outline-Manager.exe