我有来自 rauth 网站的代码:
https://github.com/litl/rauth/blob/master/examples/facebook-cli.py
(代码可以在本文末尾找到以供参考)
在命令行中运行程序将打开一个 firefox 窗口,并从 facebook 站点显示以下消息:
Success
SECURITY WARNING: Please treat the URL above as you would your password and do not share it with anyone.
当facebook预先登录时。即使未登录,facebook 登录窗口也会打开,使用用户名/密码登录后,上述消息会显示在 firefox 窗口中。
现在地址栏中生成的 URL:
https://www.facebook.com/connect/blank.html#_=_
这显然是一个不正确的,它从后续的 python 代码中给出了异常。
现在我该如何调试问题所在?
谢谢
PS:
from rauth.service import OAuth2Service
import re
import webbrowser
# Get a real consumer key & secret from:
# https://developers.facebook.com/apps
facebook = OAuth2Service(
client_id='xxxxxxx',
client_secret='yyyyyyy',
name='facebook',
authorize_url='https://graph.facebook.com/oauth/authorize',
access_token_url='https://graph.facebook.com/oauth/access_token',
base_url='https://graph.facebook.com/')
redirect_uri = 'https://www.facebook.com/connect/login_success.html'
params = {'scope': 'read_stream',
'response_type': 'token',
'redirect_uri': redirect_uri}
authorize_url = facebook.get_authorize_url(**params)
print 'Visit this URL in your browser: ' + authorize_url
webbrowser.open(authorize_url);
url_with_code = raw_input('Copy URL from your browser\'s address bar: ')
access_token = re.search('\#access_token=([^&]*)', url_with_code).group(1)
session = facebook.get_session(access_token)
user = session.get('me').json()
print 'currently logged in as: ' + user['link']