产生此问题的原因可能有多种。如果没有详细信息,我们将无法提供帮助。尝试记录一些信息将帮助我们找出错误是什么。
https://github.com/pythonforfacebook/facebook-sdk/blob/master/facebook.py
由于您使用 get_user_from_cookie 函数收到 None 。打开 facebook.py,在将产生 None 结果的行添加两个日志。然后日志可以告诉问题出在哪里。
def get_user_from_cookie(cookies, app_id, app_secret):
"""Parses the cookie set by the official Facebook JavaScript SDK.
cookies should be a dictionary-like object mapping cookie names to
cookie values.
If the user is logged in via Facebook, we return a dictionary with
the keys "uid" and "access_token". The former is the user's
Facebook ID, and the latter can be used to make authenticated
requests to the Graph API. If the user is not logged in, we
return None.
Download the official Facebook JavaScript SDK at
http://github.com/facebook/connect-js/. Read more about Facebook
authentication at http://developers.facebook.com/docs/authentication/.
"""
cookie = cookies.get("fbsr_" + app_id, "")
if not cookie:
logging.info("no cookies") # ADD LOG HERE!
return None
parsed_request = parse_signed_request(cookie, app_secret)
try:
result = get_access_token_from_code(parsed_request["code"], "",
app_id, app_secret)
except GraphAPIError:
logging.info("get access token failed") # ADD LOG HERE!!
return None
result["uid"] = parsed_request["user_id"]
return result