Facebook API and Python

30,865

Solution 1

I ran across same problem some time ago and later found out that PyFacebook isn't deeply tied up with Django. It just uses a few utils from django.

My recommendation is that you setup PyFacebook alongwith django and then play around with it using command line. To use PyFacebook you won't have to go through or even know anything about django at all.

Here's an example:

from facebook import Facebook

api_key = 'Your App API Key'
secret  = 'Your App Secret Key'

session_key = 'your infinite Session key of user'

fb = Facebook(api_key, secret)
fb.session_key = session_key

# now use the fb object for playing around

You might need to get an infinite session key which you can get from here: http://www.facebook.com/code_gen.php?v=1.0&api_key=YOUR_API_KEY

Use this code to get convert the code from above URL into infinite session key:

def generate_session_from_onetime_code(fb, code):
    fb.auth_token = code
    return fb.auth.getSession()
print generate_session_from_onetime_code(fb, session_onetime_code)

Solution 2

A new library that is available is: https://github.com/semyazza/Facebook.py

It currently support authentication and the dialog API. Planned in the near future(currently being worked on) is a wrapper around the graph API.

The project goal is to be platform agnostic, single file, and use only standard Python libraries.

Share:
30,865

Related videos on Youtube

super9
Author by

super9

I work as a developer for a startup in Singapore. Messing around with iOS in my spare time.

Updated on July 09, 2022

Comments

  • super9
    super9 almost 2 years

    Does anyone know of a good platform agnostic example or library that does Facebook authentication and Graph API access via Python?

    The official Facebook Python SDK is tied to Google App Engine and Pyfacebook is deeply woven with Django.

    I just want to be able to mess around in terminal and go through the process of authenticating a user and then doing simple requests from the Facebook API.

    Thanks.

  • super9
    super9 about 13 years
    I guess their example is just kind of shallow in that regard. I'm looking for as much hand holding as possible as Im really new to this. When I run the example given in Pyfacebook, it just fires up my browser and directs me to Facebook. There's very little comments or documentation that is available esp. for noobs.
  • sharjeel
    sharjeel about 13 years
    I agree but probably you won't find anything better than PyFacebook. Give it a shot and I'm sure you'll be able to achieve what you are trying to do. I wrote some scripts just a few days back and after some playing around I was able to do all of the stuff I wanted with PyFacebook.
  • m1k3y3
    m1k3y3 about 12 years
    do you have any documentation on how to use it? thanks!
  • Darth Coder
    Darth Coder over 8 years
    @sharjeel Thanks for this answer and including some basic code for getting started. However, I'm unable to get the URL working with my API key and proceed to get the infinite session key. Am I doing something wrong or has the procedure changed since this answer was written?

Related