Search code examples
facebookfacebook-graph-apifacebook-fqlfql.multiquery

How to make a fql multyquery with the PHP SDK


I'm trying to make a fql multy query using the PHP SDK. This is my code

try {
    $fql = array( 
        "query1" => "SELECT uid2 FROM friend WHERE uid1 = me()",
        "query2" => "SELECT name, url, pic FROM profile WHERE id IN (SELECT uid2 FROM #query1)"
    );
    //$fql = "SELECT uid2 FROM friend WHERE uid1 = me()";
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api( array(
        'method' => 'fql.multiquery',
        'query' => $fql,
    ) );
} catch ( FacebookApiException $e ) {
    error_log( print_r( $e->getMessage(), true ) );
    $user = NULL;
}

And this always returns an exception with no message

[04-May-2012 20:22:26 UTC] PHP Notice: Undefined property: FacebookApiException::$getMessage in C:\Program Files (x86)\Zend\Apache2\htdocs\wordpress\wp-content\plugins\all-in-one-event-calendar\lib\plugins\A1ecFacebookConnectorPlugin.php on line 120 [04-May-2012 20:22:26 UTC]

i'm obviously doing something wrong, what could that be?


Solution

  • Ok i found how to do this, you must use queries as a parameter, not query

    try {
        $fql = array( 
            "query1" => "SELECT uid2 FROM friend WHERE uid1 = me()",
            "query2" => "SELECT name, url, pic FROM profile WHERE id IN (SELECT uid2 FROM #query1)"
        );
        //$fql = "SELECT uid2 FROM friend WHERE uid1 = me()";
        // Proceed knowing you have a logged in user who's authenticated.
        $user_profile = $facebook->api( array(
            'method' => 'fql.multiquery',
            'queries' => $fql,
        ) );
    } catch ( FacebookApiException $e ) {
        error_log( print_r( $e->getMessage(), true ) );
        $user = NULL;
    }