|
ExampleCode
Examples of use
Featured The following code shows how to deal with most of type of transactions with the facebook server. import minifb
_FbApiKey = "xxxyyyzzz..."
_FbSecret = minifb.FacebookSecret("aaabbbccc...")
def ModPythonHandler(request):
'''FBML Canvas page receives session info from POST'''
arguments = minifb.validate(_FbSecret, request.read())
if arguments["added"] != "1":
return ServeIndexNonmember()
else:
session_key = arguments["session_key"]
uid = arguments["user"]
return ServeIndex(uid, session_key)
def UserAdded(request):
'''Facebook callback when user has added application
gets an auth_token through post that must be converted
into a session_key. Then lookup and send stuff to Facebook'''
# Parse and validate posted values
arguments = minifb.validate(_FbSecret, request.read())
auth_token = arguments["auth_token"]
# Request session_key from auth_token
result = minifb.call("facebook.auth.getSession",
_FbApiKey, _FbSecret, auth_token=auth_token)
uid = result["uid"]
session_key = result["session_key"]
# Lookup username and details
usersInfo = minifb.call("facebook.users.getInfo",
_FbApiKey, _FbSecret, 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"]
AddUserToDatabase(uid, name, photo)
# Set the users profile FBML
fbml = "<p>Welcome, new user, <b>%s</b></p>" % name
minifb.call("facebook.profile.setFBML",
_FbApiKey, _FbSecret, session_key=session_key,
call_id=True, uid=uid, markup=fbml)
|
► Sign in to add a comment
Oh thank you, I needed to know that.
But... I don't have an auth_token in my request... where do I get it from? The scenario is that I'm writing a game. The user has their turn and I want to notify the opponent that it's their turn. This is what I get in the request:
{'fb_sig_time': '1193220206.4659', 'fb_sig_added': '1', 'fb_sig_session_key': '2a8280f22e96941a96a47467-607767124', 'fb_sig_profile_update_time': '1193010529', 'fb_sig_user': '607767124', 'fb_sig_expires': '0', 'fb_sig': '...stuff...', 'fb_sig_api_key': '...stuff...', 'id': '3', 'fb_sig_friends': '902555369,etc', 'fb_sig_in_canvas': '1'}
Can I use that session_key? Where did it come from? I'm not getting this at all :-(. Thanks,
John
This code won't work anymore, as auth_token is no longer passed.
It seems that this code overall does not seem to work the documentation is poor and its the method does not correspond to the documentation. If anyone can provide me a better alternative to obtain data from facebook without wasting time of this lousy python api then let me know
It is reall darn shame that python's api is so weak to facebook. If I am out of line or totally incorrect please enlighten me
Thank You