Сначала вы должны сгенерировать de url, по которому пользователь нажимает, в аргументах вы вводите url обратного вызова:
args = {
'client_id': settings.FACEBOOK_APP_ID,
'scope': settings.FACEBOOK_SCOPE,
'redirect_uri': request.build_absolute_uri('/authentication_callback'),
}
HttpResponseRedirect('https://www.facebook.com/dialog/oauth?' + urllib.urlencode(args)
Код для обратного вызова:
token = request.GET.get('code')
args = {
'client_id': settings.FACEBOOK_APP_ID,
'client_secret': settings.FACEBOOK_APP_SECRET,
'redirect_uri': request.build_absolute_uri('/authentication_callback'),
'code': token,
}
# Get a legit access token
target = urllib.urlopen('https://graph.facebook.com/oauth/access_token?' + urllib.urlencode(args)).read()
response = cgi.parse_qs(target)
access_token = response['access_token'][-1]
# Read the user's profile information
fb_profile = urllib.urlopen('https://graph.facebook.com/me?access_token=%s' % access_token)
fb_profile = json.load(fb_profile)
# These is the info of the facebook account:
first=fb_profile['first_name']
last=fb_profile['last_name']
email=fb_profile['email']
fb_id=fb_profile['id']
Надеюсь, это поможет