我正在尝试使用 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()
但是,授权不起作用。从我的本地主机尝试,用户单击此行生成的链接:
dropboxSession.build_authorize_url(requestToken, oauth_callback = "http://localhost:5000/")
并且,进入 DropBox 授权页面,显示应用信息和允许或拒绝选项。当我单击“允许”按钮时,它会将我重定向回来,当我检查我的帐户应用程序时,新应用程序未在此处列出。回调 url 如下所示:
http://localhost:5000/dropbox/?uid={some_uid}&oauth_token={some_token}
有谁知道发生了什么?
提前致谢!