Ad

I'm Trying To Get User Friends List From Facebook Using Curl. But It Returns Empty Data

My code is:-

$user = $socialUser = Socialite::driver('facebook')->user();
$frd = $this->getFriendsFB($user->token, $user->id);

getFriendsFb() Function defination is:-

public function getFriendsFB($token, $id = null)
    {
        $url = "https://graph.facebook.com/v3.0/$id/friends?access_token=$token";
        $type = "GET";
        $out = $this->getCurlRequestForFacebook($url, $type);
        return $out;
    }

getCurlRequestForFacebook function definition is:-

public function getCurlRequestForFacebook($url, $type)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $type);
    $output = curl_exec($ch);
    $out = json_decode($output);
    curl_close($ch);
    return $out;
}

In the output, I'm getting empty data and i've 2 friends in fb A/C. Find a screenshot of output :- https://prnt.sc/jl19w2 You can found that there are 2 friends but data is empty.

Ad

Answer

Facebook only returns the list of those friends that have previously used your application. If none have used your app till now, you will get an empty array.

Ad
source: stackoverflow.com
Ad