开发者

dropbox api usage in django apps, how?

开发者 https://www.devze.com 2023-03-14 19:39 出处:网络
Coul开发者_开发技巧d 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 w

Coul开发者_开发技巧d 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:

  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'])


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/

0

精彩评论

暂无评论...
验证码 换一张
取 消