Created
March 30, 2013 15:21
-
-
Save maxcountryman/5277080 to your computer and use it in GitHub Desktop.
Tweaks to get rauth's Facebook example working with Python 3.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rauth import OAuth2Service | |
import re | |
import webbrowser | |
try: | |
read_input = raw_input | |
except NameError: | |
read_input = input | |
# Get a real client id and secret from: | |
# | |
# https://developers.facebook.com/apps | |
facebook = OAuth2Service( | |
client_id='440483442642551', | |
client_secret='cd54f1ace848fa2a7ac89a31ed9c1b61', | |
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: {url}'.format(url=authorize_url)) | |
webbrowser.open(authorize_url) | |
url_with_code = read_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}'.format(user=user['username'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment