1. 程式人生 > >如何申請使用百度PCS API來讓檔案上傳到雲端

如何申請使用百度PCS API來讓檔案上傳到雲端

一:進入 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