-2

Grr... I cant seem to get fql working. One thing, I think the docs are old because i dont think api() likes just an array. Anyway:

$user_id = $facebook->getUser();//works
$access_token = $facebook->getAccessToken();//works
$fql = 'SELECT name from user where uid = ' . $user_id;
    $ret_obj = $facebook->api(array(
                                   'method' => 'fql.query',
                            'access_token' => $access_token,
                                  'query' => $fql,
                                 ));
print_r($ret_obj);// dont work. actually I get exceptions

I've tried all kinds of combinations of params for api(), to no avail.

$user = curl('https://graph.facebook.com/'.$user_id.'?access_token='.$access_token);

does work, though.

Doug Cassidy
  • 1,796
  • 3
  • 17
  • 28

1 Answers1

6

I use this:

function fql($q, $access_token) {
    // Run fql query
    $fql_query_url = 'https://graph.facebook.com'
    . '/fql?q='. urlencode($q)
    . '&access_token=' . urlencode($access_token);
    $fql_query_result = file_get_contents($fql_query_url);


    $length = strlen(PHP_INT_MAX);
    $fql_query_result = preg_replace('/"(user_id)":(\d{' . $length . ',})/', '"\1":"\2"', $fql_query_result);

    return json_decode($fql_query_result, true);
}
antirealm
  • 408
  • 3
  • 10