FlaskでFacebook 認証ログインを実装に関して
最近flaskを習い始めたのですが...
pythonのフレームワーク、flaskを使ってFacebook認証ログインを実装しようとすると
以下のエラーメッセージが発生しました。
発生している問題・エラーメッセージ
Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/rauth/service.py", line 21, in process_token_request return tuple(data[key] for key in args) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/rauth/service.py", line 21, in <genexpr> return tuple(data[key] for key in args) KeyError: 'access_token' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "app.py", line 64, in <module> session = facebook.get_auth_session(data= data, decoder=new_decoder) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/rauth/service.py", line 556, in get_auth_session session = self.get_session(self.get_access_token(method, **kwargs)) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/rauth/service.py", line 542, in get_access_token access_token, = process_token_request(r, decoder, key) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/rauth/service.py", line 24, in process_token_request raise KeyError(PROCESS_TOKEN_ERROR.format(key=bad_key, raw=r.content)) KeyError: 'Decoder failed to handle access_token with data as returned by provider. A different decoder may be needed. Provider returned: b\'{"error":{"message":"URL\\u3092\\u8aad\\u307f\\u8fbc\\u3081\\u307e\\u305b\\u3093: \\u3053\\u306eURL\\u306e\\u30c9\\u30e1\\u30a4\\u30f3\\u306f\\u30a2\\u30d7\\u30ea\\u306e\\u30c9\\u30e1\\u30a4\\u30f3\\u306b\\u542b\\u307e\\u308c\\u3066\\u3044\\u307e\\u305b\\u3093\\u3002\\u3053\\u306eURL\\u3092\\u8aad\\u307f\\u8fbc\\u3080\\u306b\\u306f\\u3001\\u30a2\\u30d7\\u30ea\\u8a2d\\u5b9a\\u306e\\u30a2\\u30d7\\u30ea\\u30c9\\u30e1\\u30a4\\u30f3\\u306b\\u3059\\u3079\\u3066\\u306e\\u30c9\\u30e1\\u30a4\\u30f3\\u3068\\u30b5\\u30d6\\u30c9\\u30e1\\u30a4\\u30f3\\u3092\\u8ffd\\u52a0\\u3057\\u3066\\u304f\\u3060\\u3055\\u3044\\u3002","type":"OAuthException","code":191,"fbtrace_id":"Ce9GhvbOPsB"}}\''
該当のソースコード
Python3
1facebook = OAuth2Service( 2 client_id = '###########', 3 client_secret='##############', 4 name='facebook', 5 authorize_url='https://graph.facebook.com/oauth/authorize', 6 access_token_url='https://graph.facebook.com/oauth/access_token', 7 base_url='https://graph.facebook.com/' 8) 9 10redirect_uri = 'http://localhost:5000' 11 12params = { 13 'scope':'read_stream', 14 'response_type': 'code', 15 'redirect_uri': redirect_uri 16} 17 18url = facebook.get_authorize_url(**params) 19 20# url_with_token = read_input('Copy URL from your browser\'s address bar: ') 21# access_token = re.search('\#access_token=([^&]*)', url_with_token).group(1) 22 23 24def new_decoder(payload): 25 return json.loads(payload.decode('utf-8')) 26 27data = {'code': 'foobar', 28 'grant_type': 'authorization_code', 29 'redirect_uri': redirect_uri} 30 31session = facebook.get_auth_session(data= data, decoder=new_decoder) 32 33print(session.get('me').json()['username'])
試したこと
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。