[Answer]-Using facebook to login then signal to create a userprofile

1👍

Facebook: http://catherinetenajeros.blogspot.com/2013/03/facebook-login.html

 def get_profile(request, token=None):
    args = {
        'client_id': settings.FACEBOOK_APP_ID,
        'client_secret': settings.FACEBOOK_APP_SECRET,
        'redirect_uri': request.build_absolute_uri(reverse('pets:fb_callback')),
        'code': 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]

    return access_token 



def fb_login(request):
    args = {
        'client_id': settings.FACEBOOK_APP_ID,
        'scope': settings.FACEBOOK_SCOPE,
        'redirect_uri': request.build_absolute_uri(reverse('app_name:fb_callback')),
    }
    return HttpResponseRedirect('https://www.facebook.com/dialog/oauth?' + urllib.urlencode(args))



def fb_callback(request):
    access_token = get_profile(request, request.GET.get('code'))  
    fb_profile = urllib.urlopen('https://graph.facebook.com/me?access_token={0}'.format(access_token))
    fb_profile = json.load(fb_profile)

    fb_username = fb_profile.get('username', fb_profile['email'].split('@')[0])
    fb_id = fb_profile.id
    fb_email = fb_profile.email

    [.........]

Leave a comment