我需要从Facebook获取 Profiles 图片然后用户登录到Facebook登录php sdk的网络应用程序 . 然后将其显示出来
我正在使用此代码:
$fb = new Facebook\Facebook([
'app_id' => 'xxx...x',
'app_secret' => 'xx....xx',
'default_graph_version' => 'v2.4',
'default_access_token' => isset($_SESSION['facebook_access_token']) ? $_SESSION['facebook_access_token'] : 'xx..xx'
]);
try {
$response = $fb->get('/me?fields=id,name,email,picture');
$user = $response->getGraphUser();
$image = $user['picture'];
echo "<img src='$image' height='42' width='42'>";
exit; //redirect, or do whatever you want
} catch(Facebook\Exceptions\FacebookResponseException $e) {
//echo 'Graph returned an error: ' . $e->getMessage();
} catch(Facebook\Exceptions\FacebookSDKException $e) {
//echo 'Facebook SDK returned an error: ' . $e->getMessage();
}
如何获取 Profiles 图片并正确显示?
1 回答
有些错误?我正在检查facebook文档的示例,并且访问令牌作为参数传递,调用get()
https://developers.facebook.com/docs/php/howto/example_retrieve_user_profile/5.0.0
编辑 . 如果不起作用请尝试此示例:http://www.howtobloger.com/2013/10/how-to-access-app-user-name-and-profile.html