Created
July 6, 2010 02:39
-
-
Save tzangms/464933 to your computer and use it in GitHub Desktop.
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
def facebook_authorization(request): | |
url = "https://graph.facebook.com/oauth/authorize" | |
params = urllib.urlencode({ | |
'client_id': settings.FACEBOOK_APP_ID, | |
'redirect_uri': settings.FACEBOOK_REDIRECT_URI, | |
'scope': 'offline_access,read_stream,publish_stream' | |
}) | |
return redirect(url + '?' + params) | |
def facebook_verify(request): | |
code = request.GET.get('code', None) | |
if not code: | |
return HttpResponse('Bad Request') | |
url = 'https://graph.facebook.com/oauth/access_token?' | |
params = urllib.urlencode({ | |
'client_id': settings.FACEBOOK_APP_ID, | |
'redirect_uri': settings.FACEBOOK_REDIRECT_URI, | |
'client_secret': settings.FACEBOOK_APP_SECRET, | |
'code': code | |
}) | |
result = urlfetch.fetch(url + params) | |
if result.status_code == 200: | |
response = cgi.parse_qs(result.content) | |
access_token = response['access_token'][-1] | |
graph = facebook.GraphAPI(access_token) | |
profile = graph.get_object("me") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment