Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Connect: capturing user data with django-profiles and django-socialregistration

Either my google searching has completely left me or there's hardly any documentation/tutorials for django-socialregistration. Too bad, because it seems like a nice enough app. Through some trial-and-error, I have managed to get it mostly running on my site.

My question, using django-socialregistration how do I request permission for the facebook user's full name, current city and date of birth and store it in my UserProfile table (which is my AUTH_PROFILE_MODULE for django-profiles) in Django upon registration? Also, how do I post to the user's wall from Django once the connection is made?

Currently, when I click the "Connect with Facebook" button the facebook connection is made, a new Django user is created and the user is logged in with that Django account. However, no UserProfile is created and no facebook profile data is saved.

Any facebook connect gurus out there want to help the Django pony fly to Facebookland?

Setup:
- Django 1.2.1
- Python 2.5.2
- django-socialregistration 0.4.2
- django-registration 0.7
- django-profiles 0.2

alt text
"Kind sir, can you please help me find the magical Facebookland?"

like image 640
mitchf Avatar asked Oct 19 '10 22:10

mitchf


2 Answers

In facebook_js.html you need to adjust the following line, by uncommenting items that you need to get from FB:

     FB.login(handleResponse/*,{perms:'publish_stream,sms,offline_access,email,read_stream,status_update,etc'}*/);

Then, in FacebookMiddleware you can extract that data from fb_user, like this:

     facebook.GraphAPI(fb_user['access_token']).get_object('me')
like image 84
Tomasz Zieliński Avatar answered Nov 08 '22 09:11

Tomasz Zieliński


Here's another relevant nugget (source: http://github.com/flashingpumpkin/django-socialregistration/issues/closed#issue/7) Enough of these and this page will become the de facto django-socialregistration documentation ;)

question from "girasquid":

Maybe I'm just missing something, but I'm stuck here - is there a way to 'connect' accounts on other sites to an already-existing user?

For example, I've already signed up on Really Awesome Website, so I don't need to sign up again - but I'd like to connect my Facebook and Twitter accounts so that I can sign in with those as well.

Is there a way to do this already? If there isn't...how would I do it?

answer from "flashingpumpkin":

Yes there is. Just use the same template tags for Facebook Connect as you would for registration. Depending on if the user is already logged in or not it will create just the FacebookProfile object and link it to the existing user - or create both, the User object and the FacebookProfile object.

Have a look here:
http://github.com/flashingpumpkin/django-socialregistration/blob/master/socialregistration/templates/socialregistration/facebook_button.html and

http://github.com/flashingpumpkin/django-socialregistration/blob/master/socialregistration/templatetags/facebook_tags.py

like image 28
mitchf Avatar answered Nov 08 '22 08:11

mitchf