Write Facebook apps using Google AppEngine Apr 20

I hacked up minifb in order to get it to work with Google AppEngine. The result is gminifb. It uses Google's urlfetch library instead of urllib2.

To get it to work, download gminifb and place it in your application's directory. It requires simplejson, so put that in your app's directory as well.

Here's a sample webapp.py action that uses the library:

class FacebookAction(FbHandler):
  def get(self):
    arguments = gminifb.validate(FB_SECRET_KEY, self.request)
    session_key = arguments["session_key"]
    uid = arguments["user"]

    usersInfo = gminifb.call("facebook.users.getInfo",
        FB_API_KEY, FB_SECRET_KEY, session_key=session_key,
        call_id=True, fields="name,pic_square",
        uids=uid) # uids can be comma separated list
    name = usersInfo[0]["name"]
    photo = usersInfo[0]["pic_square"]

    self.render('facebook.html', {'name': name, 'photo': photo})

Thanks to Peter Shinners for writing the original minifb library. My changes were very minimal...

8 comments

8 comments

Peter Jun 02 2008

Do you use http://myapp.appspot.com/ as a callback url in facebook or just linking to it in a fbml iframe? Thx!

patrick Jun 03 2008

I use http://myapp.appspot.com/fb as the callback url (where /fb gets routed to the FacebookAction class above...). Hope that helps...

Peter Jun 04 2008

Working! But I had to use class SomeAction(MyHandler): def post(self): .... self.render(...) with all actions! Using - def get(self) - received HTTP 405 error

Mike Jun 18 2008

Thanks for sharing this. One less thing for me to worry about since I'm already new to the app engine, facebook development, and even python.

Chris Hinkle Aug 04 2008

I'm trying to make this work. Did the GAE SDK change and break this? Looks like the builtin buffer function, used to hide the secret is not supported. #Line 244 of gminifb.py b = buffer(value) #Line 520 of dev_appserver.py: __builtin__.buffer = NotImplementedFake

Rennee Aug 23 2008

Hi, good article. You have to use django as the web framework with gminifb right? Or else it wouldn't work.

Renee Aug 23 2008

ok i lied. django's not necessary, but how do you get the session_key? for some reason facebook won't return me the session_key, but I can get userid and other things.

Henrik Aug 29 2008

How is this lib working for the new facebook API? Is it working? And if not, can I help in making it work?

Add a comment

Name (required)
Email (won't be displayed)
URL (include http://)
Comment (required)