Search code examples
pythondjangofacebook-fqldjango-facebook

Retrieve data from FQL query


I'm doing a facebook integration with django-facebook so I need to retrieve data from fql queries. Here is the code:

a = request.user.get_profile().access_token
aquery = "SELECT uid, rsvp_status, start_time FROM event_member WHERE eid = 229224023873578 AND rsvp_status = 'attending'"
query = "https://api.facebook.com/method/fql.query?query=%s&access_token=%s" % (aquery, a)
return HttpResponseRedirect(query)

As it is now the code gets the access_token from the models made from django-facebook and gets all attending members for the specific event. Finally it redirects to the fql results page. I want to retrieve these results and process them - How can I do that? I tried using urllib2 and putting query like this:

response = urllib2.urlopen(query)
html = response.read()
return HttpResponse(html)

I get an error - HTTP Error 400: Bad Request. Thanks for your help in advance!


Solution

  • Ok I found the solution - Here it is:

    query = "YOUR FQL QUERY --- SEE FB API DOCUMENTATION ---" 
    b = graph.fql(query)
    

    Django-facebook has graph - import it and use it (for more info on this graph see django-facebook git code)