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?
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:
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
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!
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)
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'])
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With