我正在运行FQL查询并且我保留此错误但无法找出原因,因为错误消息告诉我什么。查询和错误是:
SELECT backdated_time, can_backdate, caption, created_time, owner, owner_comment, picture, summary, title, url FROM link WHERE owner IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND (strpos(lower(summary),"boston") >=0 OR strpos(lower(owner_comment),"boston") >=0 ) LIMIT 20
Fatal error: Uncaught Exception: 1: An unknown error occurred
thrown in /Facebook/base_facebook.php on line 1254
有谁知道为什么会出现这个错误?我正在使用Facebook PHP库。
答案 0 :(得分:1)
这很窒息,查询太大了。考虑使用多查询,朋友查询的LIMIT和一些OFFSET来翻阅数据。
fql?q={"friendsquery":"SELECT uid2 FROM friend WHERE uid1 = me() LIMIT 20 OFFSET 0","linkquery": "SELECT backdated_time, can_backdate, caption, created_time, owner, owner_comment, picture, summary, title, url FROM link WHERE owner IN (SELECT uid2 FROM #friendsquery) AND (strpos(lower(summary),'boston') >=0 OR strpos(lower(owner_comment),'boston') >=0 ) LIMIT 20"}
对于朋友列表400,此当前查询的时间为80秒。
以下是Python中的一个示例,它不是PHP,但API实现是相同的
from facepy import GraphAPI
import time
import urllib
import json
fb_dump = open('dumpfb.txt', 'w')
graph = GraphAPI('MY_ACCESS_TOKEN')
all_posts = []
offset = 0
friendsquery = 'SELECT uid2 FROM friend WHERE uid1 = me() LIMIT 20 OFFSET '+ str(offset)
linksquery = 'SELECT backdated_time, can_backdate, caption, created_time, owner, owner_comment, picture, summary, title, url FROM link WHERE owner IN (SELECT uid2 FROM #friendsquery) AND (strpos(lower(summary),"trinidad") >=0 OR strpos(lower(owner_comment),"trinidad") >=2 ) LIMIT 20'
t0 = time.time()
try:
my_posts = graph.fql({'friendsquery': friendsquery, 'linksquery': linksquery})
while my_posts["data"][0]["fql_result_set"]:
all_posts = all_posts + my_posts["data"]
offset = offset + 20
friendsquery = 'SELECT uid2 FROM friend WHERE uid1 = me() LIMIT 20 OFFSET '+ str(offset)
my_posts = graph.fql({'friendsquery': friendsquery, 'linksquery': linksquery})
t1 = time.time()
print t1-t0
fb_dump.write(json.dumps(all_posts, indent=4))
except GraphAPI.OAuthError, e:
print e.message
执行批量查询可以将查询缩短到25秒。不是很快,但订单比前两个查询更快。我没有用PHP做过,但你应该得到要点
这是一批中的20个多查询和一个/我/朋友的电话
fb_dump = open('lumpfb.txt', 'w')
graph = GraphAPI('MY_ACCESS_TOKEN')
all_posts = []
offset = 0
friendsquery = 'SELECT uid2 FROM friend WHERE uid1 = me() LIMIT 20 OFFSET '
linksquery = 'SELECT backdated_time, can_backdate, caption, created_time, owner, owner_comment, picture, summary, title, url FROM link WHERE owner IN (SELECT uid2 FROM #friendsquery) AND (strpos(lower(summary),\'trinidad\') >=0 OR strpos(lower(owner_comment),\'trinidad\') >=2 ) LIMIT 20'
t0 = time.time()
batch_request = []
try:
my_friends = graph.get("me?fields=friends")
counter = len(my_friends["friends"]["data"])
while counter > 0 :
friendsquery0 = 'SELECT uid2 FROM friend WHERE uid1 = me() LIMIT 20 OFFSET '+ str(offset)
the_query = '{"friendsquery":"'+friendsquery0+'","linksquery":"'+linksquery+'"}'
batch_item = {"method":"GET","relative_url":"fql?q=" + the_query}
batch_request.append(batch_item)
offset = offset + 20
counter = counter - 20
my_posts = graph.batch(batch_request)
for post in my_posts:
all_posts = all_posts + post['data']
t1 = time.time()
print t1-t0
except facepy.exceptions.FacepyError, e:
print e.message