Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dropbox api usage in django apps, how?

Could someone show some example about using dropbox api with django? Dropbox api is installed, readme is done, tests are done, how to go further?

like image 884
kecske Avatar asked Dec 22 '22 12:12

kecske


2 Answers

Yes, you need to understand, how oauth works. Consider the use-case, when you are trying to store uploaded files directly on user's dropbox account. First of all, you have to register a developer account on dropbox site. In your django views, a typical workflow is this:

  1. ask dropbox for a request token, (it notifies them that you will use their api soon)

    dba = auth.Authenticator(app_settings.CONFIG)

    request_token = dba.obtain_request_token()

    it's in the api's documentation how to set up the config file

  2. than you build an authentication url:

    authorize_url = dba.build_authorize_url(request_token, callback='http://...'

    the user sign in at dropbox.com, than redirected back to your site

    you should store now the request token, but it's only useful to get the access token!

  3. you use the request token to get an access token, it's now unique to the user.

    access_token = dba.obtain_access_token(request_token, 'verifier')

    leave the verifier blank, it's preserved do future usage! store the access token, you need it in any further operation(per session)

  4. here you are! you should instantiate a client, it's defined in the python-specific dropbox package

    drpbx_client = client.DropboxClient('server','content_server','port',dba,access_token)

    the client is a helper object for file operations:

    drpbx_client.put_file('dropbox', '/porn/', request.FILES['file'])

like image 105
kecske Avatar answered Jan 04 '23 03:01

kecske


You must use the Dropbox REST api:

http://www.dropbox.com/developers/docs#api-specification

It uses oauth for authentication. Detailed guide and walkthrough can be found here:

http://hueniverse.com/oauth/

like image 32
Lepi Avatar answered Jan 04 '23 03:01

Lepi