Abdullah Apaydın
Abdullah Apaydın

Reputation: 1

Facebook Query Language gives just user ids

I'm trying to print friends of user who uses my application.Using Facebook Query Language(FLQ) to do it. But query gives just user id's.How can i get usernames with profile pictures

Here is my code:

require 'facebook.php';

$facebook = new Facebook(array(
'appId'  => 'xxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxx',
'cookie' => true, // enable optional cookie support
));

$session = $facebook->getSession();
if ($session) {
try {
$some_friends = $facebook->api(array(
      'method' => 'fql.query',
      'query' => 'SELECT uid2 FROM friend WHERE uid1='.$facebook->getUser().' LIMIT 10'
    ));
} catch (FacebookApiException $e) {
error_log($e);
}
}
print_r($some_friends);

Here is the result:

Array ( 
    [0] => Array ( [uid2] => 521117187 ) 
    [1] => Array ( [uid2] => 526583873 ) 
    [2] => Array ( [uid2] => 527579769 ) 
    [3] => Array ( [uid2] => 531219912 ) 
    [4] => Array ( [uid2] => 533654770 ) 
    [5] => Array ( [uid2] => 539141589 ) 
    [6] => Array ( [uid2] => 539243220 ) 
    [7] => Array ( [uid2] => 539342366 ) 
    [8] => Array ( [uid2] => 549294033 ) 
    [9] => Array ( [uid2] => 557508969 )
     )

solved...

Upvotes: 0

Views: 706

Answers (3)

genesis
genesis

Reputation: 50976

you can get their picture by posting uid to

http://graph.facebook.com/UID/picture

example http://graph.facebook.com/557508969/picture

enter image description here

also his name by getting http://graph.facebook.com/557508969/ (JSON encoded)

Upvotes: 1

James Ford
James Ford

Reputation: 1563

FQL Subqueries are what you need to be using, as the friend table doesn't contain any more information on the users. Try this:

require 'facebook.php';

$facebook = new Facebook(array(
'appId'  => 'xxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxx',
'cookie' => true, // enable optional cookie support
));

$session = $facebook->getSession();
if ($session) {
try {
$some_friends = $facebook->api(array(
      'method' => 'fql.query',
      'query' => 'SELECT uid,name,picture FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1='.$facebook->getUser().') LIMIT 10'
    ));
} catch (FacebookApiException $e) {
error_log($e);
}
}
print_r($some_friends);

Upvotes: 0

jeni
jeni

Reputation: 440

i think you have to change your select query to

SELECT id,username,profile_pic FROM friend WHERE uid1='.$facebook->getUser().' LIMIT 10'

if i understood your question.

Upvotes: 0

Related Questions