Skip to content

Instantly share code, notes, and snippets.

@tzangms
Created July 6, 2010 02:39
Show Gist options
  • Save tzangms/464933 to your computer and use it in GitHub Desktop.
Save tzangms/464933 to your computer and use it in GitHub Desktop.
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