我有一个问题!
我通过社交功能实现了Facebook登录。我试图获取Facebook图像,但是当我显示它时,它是一个小图像(100 * 100)和一个模糊的图像。
有什么方法可以获取真实图像?
代码
public function handleFacebookCallback()
{
$driver = Socialite::driver('facebook')
->fields([
'name',
'first_name',
'last_name',
'email',
'gender',
'verified',
]);
$userSocial = $driver->user();
$finduser = User::where('facebook_id', $userSocial->id)->first();
if($finduser)
{
Auth::login($finduser);
return redirect()->route('home');
}
else
{
if(!empty($userSocial->getAvatar()))
{
$fileContents = file_get_contents($userSocial->getAvatar());
File::put(storage_path('app/public/thumbs') .'/'. $userSocial->getId() . ".jpg", $fileContents);
}
$imageUrl = $userSocial->getId() . ".jpg";
$new_user = User::create([
'name' => $userSocial->user['first_name'],
'surname' => $userSocial->user['last_name'],
'email' => $userSocial->email,
'facebook_id'=> $userSocial->id,
'image'=>$imageUrl,
]);
Auth::login($new_user);
return redirect()->route('home');
}
}
答案 0 :(得分:0)
获取化身$userSocial->getAvatar();
时,它具有指向facebook的链接,其中type参数设置为normal。
https://graph.facebook.com/v2.6/XXXXFBUSERIDXXXX/picture?type=normal
将其更改为大
https://graph.facebook.com/v2.6/XXXXFBUSERIDXXXX/picture?type=large
有效选项为:
small, normal, album, large, square