Facebook api?

10 views
Skip to first unread message

nickels

unread,
Jun 2, 2008, 12:21:29 PM6/2/08
to Google App Engine
Seems like it would be very cool to write a facebook app on the google
app engine. Any one thought of this? What would it take to port the
facebook API over to the app engine server?

Philip

unread,
Jun 2, 2008, 12:40:16 PM6/2/08
to Google App Engine
Hello

I am developing Facebook app using App Engine. I use PyFacebook
library (http://wiki.developers.facebook.com/index.php/Python). It
supports App Engine request model. It works pretty good so far.

nickels

unread,
Jun 2, 2008, 12:56:36 PM6/2/08
to Google App Engine
Philip,
Good to hear! I didn't know this was currently possible.
I am new to web programming (am an old C++ programmer) and am diving
into as many API's as possible to start!

Thanks for the link, I will check it out

Charlie

unread,
Jun 2, 2008, 3:09:56 PM6/2/08
to Google App Engine
Are you using Django for this? Do you have a sample project you could
share that one could use to set up the basics like sessions and
authentication? That'd be a huge help!

nickels

unread,
Jun 2, 2008, 3:17:30 PM6/2/08
to Google App Engine
I second Charlie's request, if you do have a sample project!
Understood, if you dont want to give away your trade secrets, though :)

Philip

unread,
Jun 2, 2008, 3:57:55 PM6/2/08
to Google App Engine
Hello guys

Trade secrets are not a concern at this point. I have to say that my
current musings with App Engine just happen to be the first experience
with Python and the whole Pythonic ecosystem (love it so far). Here's
a link (http://wiki.developers.facebook.com/index.php/
PythonPyFacebookTutorial) to tutorial that covers some of the aspects
of using PyFacebook. I personally found it easy to use the core
offered by the PyFacebook (mainly due to any previous experience with
Django). In a nutshell here's the usage scenario (please take it with
a grain of salt). Note: Facebook.create() - static method I added that
provides all the required credentials to the Facebook constructor

f = Facebook.create()

if f.check_session(self.request):

# normal workflow
else:
if not f.added:
#app needs to be adde
url2AddApp = f.get_add_url()
self.response.out.write('<fb:redirect url="%s" />' %
url2AddApp)
else:
# login

It would make sense to wrap this functionality as part of the subclass
of webapp.RequestHandler.

If check_session returned true, you are basically ready to go. Take a
look at METHODS dictionary that has all the api supported by the
Facebook class:

METHODS = {
# feed methods
'feed': {
'publishStoryToUser': [
('title', str, []),
('body', str, ['optional']),
('image_1', str, ['optional']),
('image_1_link', str, ['optional']),
('image_2', str, ['optional']),
('image_2_link', str, ['optional']),
('image_3', str, ['optional']),
('image_3_link', str, ['optional']),
('image_4', str, ['optional']),
('image_4_link', str, ['optional']),
('priority', int, ['optional']),
],

'publishActionOfUser': [
('title', str, []),
('body', str, ['optional']),
('image_1', str, ['optional']),
('image_1_link', str, ['optional']),
('image_2', str, ['optional']),
('image_2_link', str, ['optional']),
('image_3', str, ['optional']),
('image_3_link', str, ['optional']),
('image_4', str, ['optional']),
('image_4_link', str, ['optional']),
('priority', int, ['optional']),
],

'publishTemplatizedAction': [
# facebook expects title_data and body_data to be JSON
# simplejson.dumps({'place':'Florida'}) would do fine
# actor_id is now deprecated, use page_actor_id instead
('actor_id', int, []),
('page_actor_id', int, []),
('title_template', str, []),
('title_data', str, ['optional']),
('body_template', str, ['optional']),
('body_data', str, ['optional']),
('body_general', str, ['optional']),
('image_1', str, ['optional']),
('image_1_link', str, ['optional']),
('image_2', str, ['optional']),
('image_2_link', str, ['optional']),
('image_3', str, ['optional']),
('image_3_link', str, ['optional']),
('image_4', str, ['optional']),
('image_4_link', str, ['optional']),
('target_ids', list, ['optional']),
],
},

# fql methods
'fql': {
'query': [
('query', str, []),
],
},

# friends methods
'friends': {
'areFriends': [
('uids1', list, []),
('uids2', list, []),
],

'get': [],

'getAppUsers': [],
},

# notifications methods
'notifications': {
'get': [],

'send': [
('to_ids', list, []),
('notification', str, []),
('email', str, ['optional']),
],

'sendRequest': [
('to_ids', list, []),
('type', str, []),
('content', str, []),
('image', str, []),
('invite', bool, []),
],

'sendEmail': [
('recipients', list, []),
('subject', str, []),
('text', str, ['optional']),
('fbml', str, ['optional']),
]
},

# profile methods
'profile': {
'setFBML': [
('markup', str, ['optional']),
('uid', int, ['optional']),
('profile', str, ['optional']),
('profile_action', str, ['optional']),
('mobile_fbml', str, ['optional']),
],

'getFBML': [
('uid', int, ['optional']),
],
},

# users methods
'users': {
'getInfo': [
('uids', list, []),
('fields', list, [('default', ['name'])]),
],

'getLoggedInUser': [],

'isAppAdded': [],

'hasAppPermission': [
('ext_perm', str, []),
],

'setStatus': [
('status', str, []),
('clear', bool, []),
],
},

# events methods
'events': {
'get': [
('uid', int, ['optional']),
('eids', list, ['optional']),
('start_time', int, ['optional']),
('end_time', int, ['optional']),
('rsvp_status', str, ['optional']),
],

'getMembers': [
('eid', int, []),
],
},

# update methods
'update': {
'decodeIDs': [
('ids', list, []),
],
},

# groups methods
'groups': {
'get': [
('uid', int, ['optional']),
('gids', list, ['optional']),
],

'getMembers': [
('gid', int, []),
],
},

# marketplace methods
'marketplace': {
'createListing': [
('listing_id', int, []),
('show_on_profile', bool, []),
('listing_attrs', str, []),
],

'getCategories': [],

'getListings': [
('listing_ids', list, []),
('uids', list, []),
],

'getSubCategories': [
('category', str, []),
],

'removeListing': [
('listing_id', int, []),
('status', str, []),
],

'search': [
('category', str, ['optional']),
('subcategory', str, ['optional']),
('query', str, ['optional']),
],
},

# pages methods
'pages': {
'getInfo': [
('page_ids', list, ['optional']),
('uid', int, ['optional']),
],

'isAdmin': [
('page_id', int, []),
],

'isAppAdded': [
('page_id', int, []),
],

'isFan': [
('page_id', int, []),
('uid', int, []),
],
},

# photos methods
'photos': {
'addTag': [
('pid', int, []),
('tag_uid', int, [('default', 0)]),
('tag_text', str, [('default', '')]),
('x', float, [('default', 50)]),
('y', float, [('default', 50)]),
('tags', str, ['optional']),
],

'createAlbum': [
('name', str, []),
('location', str, ['optional']),
('description', str, ['optional']),
],

'get': [
('subj_id', int, ['optional']),
('aid', int, ['optional']),
('pids', list, ['optional']),
],

'getAlbums': [
('uid', int, ['optional']),
('aids', list, ['optional']),
],

'getTags': [
('pids', list, []),
],
},

# fbml methods
'fbml': {
'refreshImgSrc': [
('url', str, []),
],

'refreshRefUrl': [
('url', str, []),
],

'setRefHandle': [
('handle', str, []),
('fbml', str, []),
],
},

'data': {
'getCookies': [
('uid', int, []),
('string', str, []),
],

'setCookie': [
('uid', int, []),
('name', str, []),
('value', str, []),
('expires', int, ['optional']),
('path', str, ['optional']),
],
},
}

To get a list of current user friends that use the app, for example,
you do the following

f.friends.getAppUsers()

Which gives you a list of their uids. Most methods supported by
Facebook class take a list of fields to fetch so you have some pretty
awesome control on what you actually fetch.

Hope this helps (please correct any inaccuracies)

Chris L

unread,
Jun 3, 2008, 9:28:22 AM6/3/08
to Google App Engine
I had success with a modified version of PyFacebook available here:
http://ae-facebook.appspot.com/

nickels

unread,
Jun 3, 2008, 1:15:18 PM6/3/08
to Google App Engine
Thanks guys. Neat stuff. Beats the heck out of writing the F90 code
I'm supposed to at work!

nickels

unread,
Jun 3, 2008, 1:46:28 PM6/3/08
to Google App Engine
Chris,

I got the code to work (partially). I am able to create the
facebookapi object.

My question: are you able to run the facebook simulator and the google
app engine simulator to deveop locally, or do you
have to upload your google app each time you make a change?

Just know which will help me look into the options...

Philip

unread,
Jun 4, 2008, 5:34:28 AM6/4/08
to Google App Engine
Hello nickets

Take a look at this thread (http://groups.google.com/group/google-
appengine/browse_thread/thread/8b1e093f42062c7b/6a8e190459365767?
lnk=gst&q=facebook#6a8e190459365767). It talks about how to make app
engine local server accept external calls. In practice (maybe it is
just my awkward practice though) I upload to the server after each
build. I use fbml for my page so as far as I understand you can't
point the Facebook app callback Url to localhost since the fbml that
your page generates gets processed by Facebook servers before it is
turned into actual HTML. If you use the iframe app model though, you
can easily use localhost as the callback url.

Hope this helps (I would love to hear about other developers'
development practices)

Chris L

unread,
Jun 4, 2008, 12:04:01 PM6/4/08
to Google App Engine
I actually created 2 Facebook apps, one of them is in developer mode
and will never be seen by the public. It does callbacks right to my
dev server. I configured the server to listen on any IP address
(0.0.0.0) but in my request handlers (except the Facebook callback
handlers) I block anything that isn't localhost:

localhostOnly = True # (False on the production server)

....

if localhostOnly and
(requestHandler.request.environ['REMOTE_ADDR'] != '127.0.0.1'):
requestHandler.error(403)


Dunno if it's really the best idea, since leaving that port open
exposes me to any security risk the appengine dev server might have.
Great for testing quickly though.
Reply all
Reply to author
Forward
0 new messages