Enthusiast
Enthusiast

Reputation: 831

Unable to get Facebook Friends in PHP SDK

I want to get facebook friends using php SDK. I cannot use Latest PHP SDK as it is using namespaces and my application doesn't support namespaces. I get following permissions from user

email,user_birthday,user_status,publish_stream,offline_access,user_friends

And when the code is executed, it shows the following Facebook OATH Dialogue

enter image description here

And you can see in the image that it doens't show user friends permission.

And when I want to get user's friends using PHP SDK using following code:

    require_once(APPLICATION_PATH_LIB . "/Facebook/facebook.php");
    $facebook = new Facebook(array('appId' => $appId, 'secret' => $appSecret));
    $token_url = "https://graph.facebook.com/oauth/access_token?" .
            "client_id=" . $appId .
            "&client_secret=" . $appSecret .
            "&grant_type=client_credentials";
    $app_token = file_get_contents($token_url);
    $app_token = explode("=", $app_token);

    $app_token = $app_token[1];

    $user = $facebook->getUser();



    if ($user) {

        $user_profile = $facebook->api('/me', array('access_token' => $app_token));
        //echo '<pre>';var_dump($user_profile);die;
        $friends = $facebook->api('/me/friends', array('access_token' => $app_token));

       echo '<pre>';print_r($friends);
    }

And it is giving me following error

OAuthException: An active access token must be used to query information about the current user.

Upvotes: 1

Views: 620

Answers (2)

Steven Delrue
Steven Delrue

Reputation: 443

If you want to get the full list of your friends, you'll need the invitable_friends API. Note that this only works for facebook games.

Upvotes: 1

rm-vanda
rm-vanda

Reputation: 3158

They actually disabled this relatively recently---

You can now only get a list of facebook friends who are also using your app.

See this GraphAPI reference

(Second point under "Permissions")

There seems to be some disagreement about this, but, according to @drmarvelous, you can get the users' full list of friends if you submit your application for review and request that permission through the "Status & Review" section under your app. But, this process can take some time, and you may not even be granted the permission --

Upvotes: 1

Related Questions