Dropbox auth不适用于Python

时间:2013-04-08 22:10:44

标签: python oauth flask dropbox

我正在尝试使用Python(Flask)和DropBox API构建应用程序。我正在尝试授权用户,所以我按照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()

但是,授权无效。从我的localhost尝试,用户点击此行生成的链接:

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

然后,转到DropBox授权页面,显示允许或拒绝的应用信息和选项。当我点击“允许”按钮时,它会重定向我,当我检查我的帐户应用时,新的应用程序没有列在那里。回调网址如下所示:

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

任何人都知道发生了什么事?

提前致谢!

1 个答案:

答案 0 :(得分:0)

刚刚解决了。我没有注意到我在每次请求时都重置了request_token。