2016-12-31 102 views
0

你好朋友我想要得到朋友个人资料图片网址。获取朋友个人资料图片网址php

但我得到这个错误。

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

下面是我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; 

我怎样才能得到朋友的个人资料相片网址。

谢谢。

+0

什么是你需要一个大型的个人资料图片?我不确定是否有可能通过invitable_friends获得大版本。顺便说一句,你的API调用之间有空白,在“?”之间和“领域”。 – luschn

+0

我能够获得大图片。一切工作都无法得到一个朋友的照片。只需要检索一个或可能是两个网址。 – Nolan

回答

0

Facebook通常使用JSON作为响应格式。看着你的代码,你似乎忘了将第二个参数添加到json_decode。那么这个参数被假定为false。这意味着json_decode会将数据解码为其标准格式:对象。所以第二个参数应该是true以获取数据作为(关联)数组。

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

+0

请告诉我,我必须添加哪一行。我加了朋友给它,它给出NULL响应 – Nolan

+0

我认为,它在'get'函数中使用'json_decode'的地方。我不知道那里有什么代码。所以我不能告诉你,你必须修改哪一行。如果你正在使用一个库,你应该看看,如果你可以在调用'get'函数之前定义返回类型。 – akrys

相关问题