facebookpython-3.xfql.multiquery

FQL multiquery python


Hello I'm trying to run a FQL multiquery in python 3 and failing miserably. I can run 1 query fine however when I'm trying to run a multiquery I can't get it to work. For the sake of this question I've just used a multiquery that I;ve found online.

import urllib.request
import urllib.parse
ACCESS_TOKEN = 'xxxxxxxxxxxxxxxxx'


query1 = "SELECT sex FROM user WHERE uid=me()"
query2 = "SELECT uid, name, sex FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND not (sex in (select sex from #user_sex))  ORDER BY name"
query = {'query1':query1,'query2':query2}

params = urllib.parse.urlencode({'q': query, 'access_token': ACCESS_TOKEN})
#print (params)

url = "https://graph.facebook.com/fql?" + params
print (url)
data = urllib.request.urlopen(url).read()
print(data)

Solution

  • As @CBroe said, it doesn't make sense to use FQL anymore... You can get this info in one pass with the Graph API:

    GET /me?fields=gender,friends{id,name,gender}
    

    Be aware that your friends need to use the app too, otherwise you'll not be able to retrieve their info.