获取朋友的个人资料pic url php

Hello friends I am trying to get friends profile pic url.

But Im getting this error.

Cannot use object of type Facebook\FacebookResponse as array in /home/shortbuc/public_html/facebook/callback.php on line 25

Below is my callback.php

$helper = $fb->getRedirectLoginHelper();  
try {
    $accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
    // When Graph returns an error
    echo 'Graph returned an error: ' . $e->getMessage();
    exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
    // When validation fails or other local issues
    echo 'Facebook SDK returned an error: ' . $e->getMessage();
    exit;
 }
$friends = $fb -> get("me/invitable_friends? fields=id,first_name,picture.type(large)", $accessToken);
$friendpic = $friends['data'][0][picture]['data'][url];
echo $friendpic;

How can I get friends profile pic url.

Thanks.

Facebook usually uses JSON as response format. Looking at your code, it seems you forgot to add the second parameter to json_decode. Then this parameter is assumed as false. This means json_decode will decode the data to its standard format: objects. So the second parameter should be true to get the data as an (associative) array.

Example: https://secure.php.net/manual/en/function.json-decode.php#example-4315