Question

In one of my facebook applications i need to list the users that i have in my db (width their ids). I need their name, photo, and other details from facebook. Specifically i need to list the top 100 users (considering their points in the app).

I've tested it using fql:

$query = "select my top 100 users";
$result = mysql_query($query);

// Foreach user

while ($row = mysql_fetch_array($result)) {

    $user_id = $row['user_id'];
    $total_score = $row['total'];

    $fql = "select name from user where uid=" . $user_id;
    $param  =   array(
        'method'    => 'fql.query',
        'query'     => $fql,
        'callback'  => ''
    );

    // Get user names through fql query

    $fqlResult = $facebook->api($param);
    $user_name = $fqlResult[0]['name'];

    // Print user details, photo, name, total score..

}

Is the fql way efficient enough?

OR

Another way? Like the graph api:

function getName($id) { 

    $facebookUrl = "https://graph.facebook.com/".$id; 
    $str = file_get_contents($facebookUrl); 
    $result = json_decode($str); 
    return $result->name; 
}
Was it helpful?

Solution

Do 1 hit to Facebook with FQL using where uid=xx or uid=xx etc and get them all at once.

Also the graph API is the preferred way to communicate with Facebook however you would need to look into it further to see if you could grab details for multiple users at the same time.

Now just thinking further, don't you need to append the access_token to these calls with offline access (which is being depreciated) to get the information.

I am actually thinking a better way to write your entire app would be to capture this information when a user connects to your app and not a bulk process.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top