来自python的FQL多重查询失败,并使用unicode查询 [英] FQL multiquery from python fails with unicode query

查看:170
本文介绍了来自python的FQL多重查询失败,并使用unicode查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用python 2.6.5和facebook-sdk 0.3.2这个:

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

返回一个空列表,但这个

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

如果任何查询是unicode字符串,结果将是 [] ,没有错误。



Facebook开发者支持建议我在stackoverflow上发问题。他们的解释是,由于没有人报告这个错误,这可能是我做错了。所以他们关闭了错误



关于如何处理这个问题的想法?

解决方案

这是基于facebook.py库如何处理查询。对Facebook的查询最终需要进行网址编码。



所以,通过facebook.py源代码

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

最终成为



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



哪些与

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

其中作为

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

作为



查询%3D%7B%27example%27%3A + u%27SELECT + uid2 + FROM + friend + WHERE + uid1 +%3D +我%28%29%27%7D



请注意,没有处理 u 对于unicode部分,在发送到facebook.py库中的urlencode之前已完成。



https://api.facebook.com ,对此没有回复,但如果您在graph.facebook.com端点上执行相同操作你会注意到


(#601)解析器错误:意外的'{'在位置0


基本上它会阻塞你的查询。



尝试处理你的Unicode后发送Url Encoding


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?

解决方案

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

这篇关于来自python的FQL多重查询失败,并使用unicode查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆