Search code examples
pythondjangofacebookfacebook-graph-apidjango-facebook

Django-facebook. How to use a user's profile from other apps(not django-facebook)


I'm new to django. Now I just added django-facebook to my project. The installation went fine, everything seems working.

Now I'm trying to use user's profile like name,facebookID, etc. to other apps beside django-facebook. I tried to use

from open_facebook import OpenFacebook

def create_bets(request):
            graph = OpenFacebook(access_token)
            facebook.set('me/feed', message='check out fashiolista',
         url='http://www.fashiolista.com')
    return render_to_response('createbets.html', args)

it doesn't work. I'm getting an error that access_token doesn't exist. Could anyone suggest me a solution please?


Solution

  • Use this godjango.com video:

    https://godjango.com/13-django-social-auth-101/

    It will give you a walk through of how to create social logins using OAuth. It uses GitHub in the video example. Within the django-social-auth package, you can find out how to install and use it here:

    http://django-social-auth.readthedocs.org/en/latest/installing.html

    For Facebook you need to look in the documentation or the package itself for the name of the access token. I will give it to you here just in case though. They are:

    FACEBOOK_APP_ID and FACEBOOK_API_SECRET

    In your settings.py you can set them up as so using environmental variables:

    FACEBOOK_APP_ID = os.environ['FACEBOOK_APP_ID']
    FACEBOOK_API_SECRET = os.environ['FACEBOOK_API_SECRET']
    

    You need to get the actual APP_ID and API_SECRET through your Facebook account. You will want to use the developer Facebook site to create an App and then generate the API credentials. The web address for this is:

    https://developers.facebook.com

    Hope this helps. Put these together and you will have social logins for your web app.