我正在使用python tornado 4.1。我正在尝试从他们的演示登录facebook,但它会抛出错误。我为错误添加了屏幕截图。
错误:
AuthError: Facebook auth error: HTTPResponse(_body=None,buffer=<_io.BytesIO object at 0x29f0290>,code=400,effective_url='https://graph.facebook.com/oauth/access_token?client_secret=&code=&client_id=&redirect_uri=http%3A%2F%2Fsoctag.com%2F%2Fauth%2Ffacebooklogin',error=HTTPError('HTTP 400: Bad Request',),headers={'Content-Length': '190', 'Facebook-Api-Version': 'v1.0', 'Expires': 'Sat, 01 Jan 2000 00:00:00 GMT', 'X-Fb-Debug': 'fKw1RAojsZPT2jl7ErDX4S6c2ROg8TgV1KqFn3Yexc9jgJetmP4K0nFZTrATG7cH5ESLJZ51HyACUJQszv5Fmw==', 'X-Fb-Rev': '1685640', 'Connection': 'close', 'Pragma': 'no-cache', 'Cache-Control': 'no-store', 'Date': 'Mon, 13 Apr 2015 11:18:34 GMT', 'Access-Control-Allow-Origin': '*', 'Content-Type': 'text/javascript; charset=UTF-8', 'Www-Authenticate': 'OAuth "Facebook Platform" "invalid_code" "Error validating verification code. Please make sure your redirect_uri is identical to the one you used in the OAuth dialog request"'},reason='Bad Request',request=<tornado.httpclient.HTTPRequest object at 0x2a2edd0>,request_time=0.5871150493621826,time_info={})
Scrrenshoot
代码:
class AuthFacebookLoginHandler(tornado.web.RequestHandler, tornado.auth.FacebookGraphMixin):
@tornado.gen.coroutine
def get(self):
if self.get_argument("code", False):
user = yield self.get_authenticated_user(
redirect_uri=Helper.url('/auth/facebooklogin'),
client_id=self.settings["facebook_api_key"],
client_secret=self.settings["facebook_secret"],
code=self.get_argument("code"))
self.redirect("/auth/facebookmain")
else:
yield self.authorize_redirect(
redirect_uri=Helper.url('/auth/facebooklogin'),
client_id=self.settings["facebook_api_key"],
extra_params={"scope": "read_stream"})
class AuthFacebookMainHandler(tornado.web.RequestHandler, tornado.auth.FacebookGraphMixin):
@tornado.gen.coroutine
def get(self):
new_entry = yield self.facebook_request(
"/me/feed",
post_args={"message": "I am posting from my Tornado application!"},
access_token=self.current_user["access_token"])
if not new_entry:
# Call failed; perhaps missing permission?
yield self.authorize_redirect()
return
self.finish("Posted a message!")
答案 0 :(得分:1)
您的错误消息有线索:
请确保您的redirect_uri与您使用的redirect_uri相同 OAuth对话框请求
检查以确保您的网址与Facebook中配置的网址相同。 您在基本设置下的Facebook配置页面中的网站网址必须与您网页的网址相同。
如果您是从localhost进行测试,则可以更改/ etc / hosts以将测试域映射到127.0.0.1。
别忘了在Facebook内部,您可以创建具有不同配置的应用程序的测试版本。
我通常至少拥有生产,测试和开发版本。