Tags:
2011-03-11

Facebook Python SDK Support For FQL Queries 

If you're using the Facebook SDK for python you may have noticed that it does not support making FQL queries.  If you need to be able to make FQL queries you can simply add the following function to the GraphAPI class in the facebook.py file (note that this code uses urllib2 because urllib may not always support SSL):

def fql(self, fql, args=None):
	if not args: args = {}
	args["query"], args["format"] = fql, "json"
	if self.access_token:
		args["access_token"] = self.access_token
	file = urllib2.urlopen("https://api.facebook.com/method/fql.query?" + urllib.urlencode(args))
	try: response = _parse_json(file.read())
	finally: file.close()
	if type(response) == dict and response.get("error_code"):
		raise GraphAPIError(str(response["error_code"]), response["error_msg"])
	return response

And then you can use this code to check if a user has given a particular permission to your app for instance.

import facebook
fbc = facebook.get_user_from_cookie(cookies, _appid, _appsec)
graph = facebook.GraphAPI(fbc["access_token"])
print(graph.fql("select publish_stream from permissions where uid = me()"))




« PREV PAGE
Unknown URL Type: https Facebook Python SDK
NEXT PAGE »
minON – Minimized Object Notation