Home > Γενικά > Curling from bash to Yandex Disk API

Curling from bash to Yandex Disk API

5556772My incentive was to create an app that reads files from my Yandex Disk (using the Yandex Disk API) using the bash from a Linux box. Unfortunately there is no much documentation in the Web (namely Google) about using the Disk API from the Web so I decided to write this short guide.

(1) Login with your Yandex credentials to https://oauth.yandex.com/ and create a new app. Give title, description and at the Scope section select the subscopes that you really need (or all of them) form Yandex Disk REST API.

(2) Press the Submit button and at the next screen you will be presented with the ID, Password and Callback URL of your new app. Keep those in an open tab.

(3) Fire up your favorite browser and authorize the app to access your Yandex Disk files using the following URL:

https://oauth.yandex.com/authorize?response_type=token&client_id=<ID>&devide_id=<PICK_A_DEVICE_ID>&device_name=<PICK_A_DEVICE_NAME>&display=popoup&force_confirm=yes&state=stateString

<ID> is your app ID you kept open in a browser tab earlier. In <PICK_A_DEVICE_ID> and <PICK_A_DEVICE_NAME> you can put whatever makes sense for your app.

Press Allow and you will be presented with the OAuth Token. Copy it to the clipboard.

(4) Open your favorite terminal and get some info about your Yandex Disk using the following curl command:

curl -X GET -H ‘Accept: application/json’ -H ‘Content-Type: application/json’ -H ‘Authorization: OAuth <OAuth token>’ https://cloud-api.yandex.net/v1/disk/

where <OAuth token> is exactly what the name says.

(5) To download a file from your Disk use the following curl command:

curl -X GET -H ‘Accept: application/json’ -H ‘Content-Type: application/json’ -H ‘Authorization: OAuth <OAuth token>’ https://cloud-api.yandex.net/v1/disk/resources/download?path=%2F<filename>

where <filename> is the name of the file or the path of the file that you want to download. The responce is a json stucture that contains the URL needed to download the file (href key).

Hope it helps someone!

Happy curling

 

Categories: Γενικά Tags: , , ,
  1. No comments yet.
  1. No trackbacks yet.