Sunday, January 23, 2011

Django Social-registration and the Facebook API

I am creating a Pinax based website that will require users to have an account and to login. I wanted users with Facebook accounts to be able to use OAuth and Facebook to create their account on my site. I also wanted to use data from Facebook to fill in as much of the user profile as possible. To accomplish this, I installed the app social-registration.

Facebook provides basic info such as first name and last name without extended permissions. Email address requires extended access. Extended access can be requested using the scope parameter during facebook login.

Social-registration has some javascript (templates/socialregistration/facebook_js.html ) that you can put in your templates to allow users to login with facebook. In that js file, the code that adds the scope parameter is commented out:

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

Uncommenting that code solves part of the problem. However, the perms list is really just a placeholder. status_update and etc are not valid perms, but the rest are. Remove those and it should work.

If you put the social-registration middleware in your settings, then you can access all the users facebook info in your views using:

data_dict=request.facebook.graph.get_object('me')

2 comments:

  1. I'm confused by the first sentence in your third paragraph. Pinax doesn't use social-registration to handle openID and Facebook.

    ReplyDelete
  2. James,

    Thanks for all your contributions to the Django community! I really admire your work.

    I am sorry for the confusion. My mistake. I forgot I installed social-registration and thought it came as part of the Pinax bundle.

    I will edit the post.

    Chuck

    ReplyDelete