fql.multiquery returning empty array

匆匆过客 提交于 2019-12-08 12:01:11

问题


I'm am trying to query all the photo albums of a page and get each albums cover photo. Below is the code I have that returns an empty result.

I am able to make both the queries separately without the problem, so it is not a permissions issue.

$album_fql = "SELECT aid, owner, name, object_id, cover_pid, cover_object_id 
              FROM album
              WHERE owner = 'xxxxxxx'";

$albumpic_fql = "SELECT pid, src_small
                 FROM photo 
                 WHERE pid IN (SELECT cover_pid FROM #query1)";

$album_param = array(
                 'method'    => 'fql.multiquery',
                 'queries'   => '{"query1":"' . $album_fql . '", "query2":"' . $albumpic_fql . '"}');

$album_fqlResult = $facebook->api($album_param);

print_r($album_fqlResult);

Any ideas?


回答1:


you can do that in a nested query rather than as a multi query.

SELECT pid, src_small 
FROM photo 
WHERE pid in (SELECT cover_pid FROM album where owner={page id here})

for example here's the list of album covers I got from CocaCola's Facebook page

SELECT pid, src_small 
FROM photo 
WHERE pid in (SELECT cover_pid FROM album where owner=40796308305)
LIMIT 5

returned:

{
  "data": [
    {
      "pid": "40796308305_2143765",
      "object_id": 110516463305,
      "src_small": "https://fbcdn-photos-a.akamaihd.net/hphotos-ak-snc1/6570_110516463305_40796308305_2143765_6253354_t.jpg"
    },
    {
      "pid": "40796308305_8753877",
      "object_id": "10150500888203306",
      "src_small": "https://fbcdn-photos-a.akamaihd.net/hphotos-ak-ash4/398389_10150500888203306_40796308305_8753877_1814220329_t.jpg"
    },
    {
      "pid": "40796308305_8751674",
      "object_id": "10150500434253306",
      "src_small": "https://fbcdn-photos-a.akamaihd.net/hphotos-ak-ash4/407475_10150500434253306_40796308305_8751674_1040781388_t.jpg"
    },
    {
      "pid": "40796308305_8742570",
      "object_id": "10150498588158306",
      "src_small": "https://fbcdn-photos-a.akamaihd.net/hphotos-ak-ash4/396541_10150498588158306_40796308305_8742570_1378170213_t.jpg"
    },
    {
      "pid": "40796308305_8742259",
      "object_id": "10150498546173306",
      "src_small": "https://fbcdn-photos-a.akamaihd.net/hphotos-ak-snc7/402667_10150498546173306_40796308305_8742259_287537096_t.jpg"
    }
  ]
}

If you want to try your multiquery, then try to name the queries starting at index 0 instead of 1. e.g. query0 and query1 This is the only way the C# SDK allows it, maybe the php SDK requires that too.




回答2:


Finally figured it out. I had to merge the queries into 1 variable and escape the single quotes.

    $queries = '{

"query1" : "SELECT aid, name, cover_pid FROM album WHERE owner = \'xxxxxxxxxxx\'",

"query2" : "SELECT aid, images FROM photo WHERE pid IN (SELECT cover_pid FROM #query1)"

}';


来源:https://stackoverflow.com/questions/8663836/fql-multiquery-returning-empty-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!