How to make fql.multiquery using facebook php sdk 3.0

Now I am moving from 2.x PHP SDK to 3.x. All multiquery calls are broken, and I could not figure out how to solve them.

Facebook connects to the login using oauth javascript and allows you to access data for the current user on the server side. I assume this confirms that my access token is legal.

I tried the following code options and got errors every time:

Old way:

        $id = $fb->getUser(); // RETURNS A VALID USER ID
        $fql = '{ "friends" : "SELECT uid FROM user WHERE has_added_app=1 and uid IN (SELECT uid2 FROM friend WHERE uid1 = '.$id.')", "profiles" : "SELECT uid, name, pic_square FROM user WHERE uid IN (SELECT uid FROM #friends)"}';

        $response = $fb->api( array('method' => 'fql.multiquery','queries' => $fql));


Gives error: PHP Fatal error: Uncaught Exception: 102: User session required \ n thrown



The supposed new way to do this is:

        $id = $fb->getUser(); // RETURNS A VALID USER ID
        $fql = '{ "friends" : "SELECT uid FROM user WHERE has_added_app=1 and uid IN (SELECT uid2 FROM friend WHERE uid1 = '.$id.')", "profiles" : "SELECT uid, name, pic_square FROM user WHERE uid IN (SELECT uid FROM #friends)"}';

        $response = $fb->api( array('method' => 'fql.query','query' => $fql));

Gives an error: PHP Fatal error: Not available Exception: 601: Error Parser: unexpectedly '{' at position 0

Any help on understanding how to do multiple instances using the new PHP SDK is appreciated.

+1
2

fql API :

$user = $facebook->getUser();
if ($user) {
  try {
    $fql = urlencode("SELECT uid, name, pic_square FROM user WHERE is_app_user = 1 AND uid IN (SELECT uid2 FROM friend WHERE uid1 = $user)");
    $response = $facebook->api("/fql?q={$fql}");
  } catch (FacebookApiException $e) {
    echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
    $user = null;
  }
}

is_app_user has_added_app !

+3

:

  $common_fields_fql = 'SELECT uid, email, contact_email, first_name, last_name, birthday_date, pic_square, sex, hometown_location, current_location, is_app_user FROM user WHERE uid ';
  $fql = array(
    'friends' => 'SELECT uid2 FROM friend WHERE uid1 = me()',
    'friends_details' => $common_fields_fql . 'IN (SELECT uid2 FROM #friends)',
    'me' => $common_fields_fql . '= me()',
    'family' => 'SELECT uid, birthday, name, relationship FROM family WHERE profile_id = me()',
  );
  $details = $facebook->api(array(
    'method'   => 'fql.multiquery',
    'queries'  => $fql,
  ));
+1

All Articles