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']