我在我的 Django v1.5.3 应用程序中使用为 Dropbox API v1.6 描述的DropboxOAuth2Flow方法,并且在重定向到 Dropbox oauth2 授权页面时出现 400 错误。
当我转到我的 dropbox_auth_start URL 时,我被重定向到:
然后发生400错误。
顺便把“dropbox-auth-csrf-token”写在会话文件中。
我的 Django 代码:
视图.py
def get_dropbox_auth_flow(web_app_session):
redirect_uri = "http://www.mydomain.com"
return DropboxOAuth2Flow('blahblahblah', 'blehblehbleh', redirect_uri, web_app_session, "dropbox-auth-csrf-token")
# URL handler for /dropbox-auth-start
def dropbox_auth_start(request):
authorize_url = get_dropbox_auth_flow(request.session).start()
return HttpResponseRedirect(authorize_url)
# URL handler for /dropbox-auth-finish
def dropbox_auth_finish(request):
try:
access_token, user_id, url_state = get_dropbox_auth_flow(request.session).finish(request.GET)
except DropboxOAuth2Flow.BadRequestException, e:
http_status(400)
except DropboxOAuth2Flow.BadStateException, e:
# Start the auth flow again.
return HttpResponseRedirect("http://www.mydomain.com/dropbox_auth_start")
except DropboxOAuth2Flow.CsrfException, e:
return HttpResponseForbidden()
except DropboxOAuth2Flow.NotApprovedException, e:
raise e
except DropboxOAuth2Flow.ProviderException, e:
raise e
网址.py
from django.conf.urls import patterns, url, include
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^dropbox_auth_start/?$',views.dropbox_auth_start),
url(r'^dropbox_auth_finish/?$',views.dropbox_auth_finish),
)