如何申请使用百度PCS API来让文件上传到云端

来源:互联网 发布:武汉大学图书馆数据库 编辑:程序博客网 时间:2024/05/21 09:38
一:进入 http://developer.baidu.com/console#manage/apilist!
二:记录下API Key和Secret Key
三:Server端使用百度OAuth2.0授权调用开放API流程
详细文档:http://developer.baidu.com/wiki/index.php?title=docs/oauth/application

1.在浏览器中输入:https://openapi.baidu.com/oauth/2.0/authorize?response_type=code&client_id={API Key}&redirect_uri=oob
2. 复制下授权码
3. 获取到Access Token
在浏览器输入:
https://openapi.baidu.com/oauth/2.0/token?grant_type=authorization_code&code={Access Token}&client_id={API Key}&client_secret={Secret Key}&redirect_uri=oob从而获取到Access Token
输入结果如:

{    "access_token": "1.a6b7dbd428f731035f771b8d15063f61.86400.1292922000-2346678-124328",    "expires_in": 86400,    "refresh_token": "2.385d55f8615fdfd9edb7c4b5ebdc3e39.604800.1293440400-2346678-124328",    "scope": "basic email",    "session_key": "ANXxSNjwQDugf8615OnqeikRMu2bKaXCdlLxn",    "session_secret": "248APxvxjCZ0VEC43EYrvxqaK4oZExMB",}
http://developer.baidu.com/wiki/index.php?title=docs/pcs/guide/token_authorize

四、可以通过api操作云盘了
文档见:http://developer.baidu.com/wiki/index.php?title=docs/pcs/rest/file_data_apis_list
举例:在vps端获取磁盘容量信息
wget -O - "https://pcs.baidu.com/rest/2.0/pcs/quota?method=info&access_token={token}" 2>/dev/null
                                             
0 0
原创粉丝点击