27

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
  • 29,181
  • 39
  • 119
  • 172
  • 1
    https://github.com/facebook/python-sdk seems to be dead now. – Divick Aug 01 '12 at 14:51
  • 2
    Update: http://pypi.python.org/pypi/facebook-sdk seems to be good. – Babu Aug 06 '12 at 10:42
  • Do you know [django-fukinbook](https://github.com/digitalinc/django-fukinbook)? We've developed this at [dp6](http://www.dp6.com.br/) and it's opensource. –  May 02 '13 at 12:34

3 Answers3

25

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)
sharjeel
  • 5,825
  • 7
  • 34
  • 49
  • 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. – super9 Mar 04 '11 at 10:41
  • 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. – sharjeel Mar 04 '11 at 11:08
  • @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? – Darth Coder Jul 26 '15 at 21:19
3

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.

Justin Weeks
  • 368
  • 3
  • 5
0

How about taking the Facebook Python SDk itself and stripping off the GAE part from it and using the other API calls only?

Senthil Kumaran
  • 54,681
  • 14
  • 94
  • 131