简体   繁体   中英

Dropbox auth is not working on Python

I'm trying to build an app using Python ( Flask ) and DropBox API. I'm trying to authorize an user, so I followed up the tutorial for python.

from flask import Flask, render_template, url_for
from dropbox import client, rest, session

# Dropbox Settings
APP_KEY     = 'gb83a6gpdo4kba6'
APP_SECRET  = 'w5q0yhj9ikiw39g'
ACCESS_TYPE = 'app_folder'

# Flask Config
DEBUG = True

app = Flask(__name__)
app.config.from_object(__name__)

@app.route("/")
def home():

    dropboxAccount = dropboxAccessToken = dropboxClient = None

    # Dropbox Auth
    dropboxSession = session.DropboxSession(app.config['APP_KEY'], app.config['APP_SECRET'], app.config['ACCESS_TYPE'])
    requestToken   = dropboxSession.obtain_request_token()

    try:
        dropboxAccessToken = dropboxSession.obtain_access_token(requestToken)

        dropboxClient      = dropboxClient.DropboxClient(dropboxSession)
        dropboxAccount     = dropboxClient.account_info()
    except Exception, e:
        print e
        dropboxAuthUrl = dropboxSession.build_authorize_url(requestToken, oauth_callback = "http://localhost:5000/")

    context = {
        'dropboxAuthUrl' : dropboxAuthUrl,
        'dropboxAccount' : dropboxAccount
    }

    return render_template('layout.html', context = context)

if __name__ == "__main__":
    app.run()

But, authorization isn't working. Trying from my localhost, the user clicks on the link generated by this line:

dropboxSession.build_authorize_url(requestToken, oauth_callback = "http://localhost:5000/")

And, go to DropBox authorization page, displaying app info and options to allow or refuse. When I click in "Allow" button, it redirects me back, and when I check my account apps, the new app isn't listed there. The callback url looks like this:

http://localhost:5000/dropbox/?uid={some_uid}&oauth_token={some_token}

Anyone knows whats is going on?

Thanks in advance!

Just solved. I didn't notice that I was reseting request_token on every request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM