1

Using python 2.6.5 and facebook-sdk 0.3.2 this:

import facebook
api = facebook.GraphAPI(token)
api.fql({'example':u"SELECT uid2 FROM friend WHERE uid1 = me()"})

returns an empty list, but this

api.fql({'example':"SELECT uid2 FROM friend WHERE uid1 = me()"})

works. If any of the queries are unicode strings, the result will be [] with no error.

Facebook developer support suggested I ask on stackoverflow what's wrong. Their explanation was that since nobody else has reported this bug, that it's probably something I'm doing wrong. So they closed the bug.

Thoughts on how to deal with this?

Leopd
  • 41,333
  • 31
  • 129
  • 167
  • Is it the equals or ( ) characters that are causing the failure? What happens if you run this: `api.fql({'example':u"SELECT uid2 FROM friend"})` Does that return an empty list as well? – Eric Leschinski Sep 17 '12 at 17:42
  • Yes, that also returns empty list. Any unicode query returns empty list with no error messages. – Leopd Sep 17 '12 at 17:47
  • If you put a syntax error into the query, will you get an error then? What does this do? `api.fql({'example':u"SELECT uid2 FROM foobar"})` ? – Eric Leschinski Sep 17 '12 at 17:54
  • Empty list. Same with `api.fql({'example':u"SELECT amateur-hour from facebook developer support!"})` – Leopd Sep 17 '12 at 18:04
  • The unicode string doesn't make it to fql validation, so there is a problem with interpreting the unicode characters themselves. What if you concatenate a regular string with a single unicode space at the end, I'm not sure how you concatenate in python, something like this: `api.fql({'example':"SELECT uid2 FROM friend WHERE uid1 = me() " + u" "})` ? Will you get the correct results or emptystring? – Eric Leschinski Sep 17 '12 at 18:11

2 Answers2

2

It's based on how the facebook.py libraries handles the queries. Queries to Facebook all end up needing to be URL encoded.

So, digging through the facebook.py source

api.fql({'example':"SELECT uid2 FROM friend WHERE uid1 = me()"})

ends up as

queries%3D%7B%27example%27%3A+%27SELECT+uid2+FROM+friend+WHERE+uid1+%3D+me%28%29%27%7D

Which matches properly as

queries={'example': 'SELECT uid2 FROM friend WHERE uid1 = me()'}

where as

api.fql({'example':u"SELECT uid2 FROM friend WHERE uid1 = me()"})

ends up as

queries%3D%7B%27example%27%3A+u%27SELECT+uid2+FROM+friend+WHERE+uid1+%3D+me%28%29%27%7D

Notice that no handling of u for the unicode part was done before sending to urlencode in the facebook.py library.

https://api.facebook.com, returns no response to this but if you did the same at the graph.facebook.com endpoint you will notice

(#601) Parser error: unexpected '{' at position 0."

Basically, it chokes on your query.

Try dealing with your Unicode before sending off for Url Encoding

phwd
  • 19,975
  • 5
  • 50
  • 78
0

Maybe the problem is that you are mixing and matching the ASCII string on the left parameter with 'example', and using unicode on the right for the query string. Try this:

api.fql({u'example':u"SELECT uid2 FROM friend WHERE uid1 = me()"})

Try it the other way like this:

api.fql({u'example':"SELECT uid2 FROM friend WHERE uid1 = me()"})

I've known to show respect for the wild wooly world of unicode, maybe you are not encoding your ascii string correctly? Maybe try assembling your unicode string character by character with the unichr(...) command.

If fiddling around with these doesn't fix the problem, then the conclusion is that the fql function pukes when passed unicode. The work around is to always use ASCII strings.

Source: http://docs.python.org/howto/unicode.html

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335