Jonathan Petitcolas
Jonathan Petitcolas

Reputation: 4574

Facebook : how to get number of friends?

I would like to be able to retrieve some people number of friends on Facebook. However, I got some issue to achieve this goal. I tried two different ways:

1. With FQL:

I tried following query:

SELECT username, friend_count
FROM user
WHERE username = jonathan.petitcolas

But, as you can see, the friend_count property is always null. On my public profile, and also on other profiles.

2. With Facebook PHP SDK

Then, I installed the Facebook PHP SDK, created an application, and did the following:

$facebook = new \Facebook(array(
    'appId' => 'XXX',
    'secret' => 'XXX'
));

$friends = $facebook->api('/jonathan.petitcolas/friends');

Then I got the following exception:

[FacebookApiException]
(#604) Can't lookup all friends of 676944843. Can only lookup for the logged in user or the logged in user's friends that are users of your app.

Indeed, I am logged in with another user.

So, is it possible to retrieve number of friends of a public profile on Facebook? Is so, how to do this?

Thanks a lot! :)

Upvotes: 0

Views: 747

Answers (1)

C3roe
C3roe

Reputation: 96316

I tried following query:

SELECT username, friend_count
FROM user
WHERE username = jonathan.petitcolas

But, as you can see, the friend_count property is always null. On my public profile, and also on other profiles.

Nope, it’s not always null. If I do that query with my own user name (and correcting the syntax error in your query), I get back the correct number of friends. Only if I authenticated that app making the query, of course.

So, is it possible to retrieve number of friends of a public profile on Facebook?

Nope.

That says enough already:

“Can only lookup for the logged in user or the logged in user's friends that are users of your app.”

Upvotes: 1

Related Questions