Multiquery:返回空数组

时间:2012-10-08 17:39:13

标签: php facebook facebook-graph-api

$queries = '{"query1":"SELECT pid, src, link, caption, like_info, created FROM photo WHERE aid in ( SELECT aid FROM album WHERE owner = me() AND type = \"profile\" AND name = \"Profile Pictures\" ORDER BY created ASC LIMIT 1)","query2":"SELECT pid, src, link, caption, created, like_info FROM photo WHERE aid in ( SELECT aid FROM album WHERE owner = me() AND type = \"profile\" AND name = \"Profile Pictures\" ORDER BY created DESC LIMIT 1)"}';    
$multiquery = "https://api.facebook.com/method/fql.multiquery?queries=" . urlencode($queries) . "&format=json&" . $access_token;
$res = json_decode(file_get_contents($multiquery), TRUE);

但是当执行两个单独的查询时,它工作正常。这有什么问题?

我只想获取第一张和最后一张个人资料照片

1 个答案:

答案 0 :(得分:1)

一些评论:

执行此操作的最佳方法是使用PHP SDK而不使用file_get_contents

您正在使用旧的REST API网址,该网址已弃用。您应该使用Graph API网址:https://graph.facebook.com/fql?q=

您的$access_token变量是否包含查询字符串的&access_token=部分?

最后,为了保持您的查询,我发现最好的方法是将这些作为数组的元素添加到查询名称作为键,例如:$fql['query1'] = 'SELECT ...'然后使用json_encode(preg_replace('/\s+/', ' ', $fql))将它们组合成无错误的json。