2012-02-25 99 views
0

我可以批量請求中使用FQL多查詢嗎?我還沒有找到谷歌的例子。批量請求中的FQL多查詢

我運行此查詢

[{\"method\":\"GET\", 
\"relative_url\":\"fql?q= 
    {\"posts\":\"SELECT post_id, actor_id, source_id, target_id, message, created_time FROM stream WHERE source_id = ... LIMIT 0, 10\"}\, 
    {\"users\":\"SELECT uid, name FROM users WHERE uid IN (SELECT actor_id FROM #posts) LIMIT 0, 10\"} 
\"}] 

但在回答我得到:

HttpResponse: 400: {"error":{"message":"batch parameter must be a JSON array","type":"GraphBatchException"}} 

回答

3

Batching feature返回此消息,當您提交批處理大小1.例如

curl -k -F 'access_token=...' \ 
    -F 'batch=[{"method":"GET","relative_url":"me"}]' https://graph.facebook.com 

給出了相同的錯誤,而

curl -k -F 'access_token=...' \ 
    -F 'batch=[{"method":"GET","relative_url":"me"}, \ 
    {"method":"GET","relative_url":"me"}]' https://graph.facebook.com 

按預期工作。

對我來說,以下工作:

curl -k -F 'access_token=...' \ 
    -F 'batch=[{"method":"POST","relative_url":"method/fql.multiquery?queries={\"q1\":\"SELECT uid, rsvp_status FROM event_member WHERE eid=199886676776200\",\"q2\":\"SELECT name, url, pic FROM profile WHERE id IN (SELECT uid FROM #q1)\"}"}, \ 
    {"method":"GET","relative_url":"me"}]' https://graph.facebook.com 
+0

謝謝你的例子! – 2012-02-26 10:21:26

+0

@Richard Barnett 有沒有辦法在一次調用中使用批量請求與fql查詢圖形API結果? – user1105951 2014-03-01 23:07:17

+0

@Richard我將如何使用你最後一個使用PHP SDK的例子?謝謝。 – Ali 2014-04-08 11:44:55

0

我用PHP SDK來構建這種請求。以下是從特定用戶的朋友的牆上提取給定用戶的帖子的示例。

$req = array('method' => 'POST', 
     'relative_url'=>"method/fql.multiquery?queries={ 
     \"q1\":\"SELECT+post_id,actor_id,source_id,message,comment_info.comment_count,created_time,likes+FROM+stream+WHERE+actor_id=me()+AND+source_id=$id+AND+message!=''+limit+100\", 
     \"q2\":\"SELECT+id,post_id,fromid,text,time,likes,user_likes+FROM+comment+WHERE+post_id+IN+(SELECT+post_id+FROM+#q1)\", 
     \"q3\":\"SELECT+name,uid+FROM+user+WHERE+uid+IN+(SELECT+fromid+FROM+#q2)\"}"); 


$requests[] = $req; 

$batch_result = $facebook->api('/?batch='.urlencode(json_encode($requests)), 'POST');