Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel socialite facebook avatar

Im using Laravel 5.2 with Socialite. I am able to pull out the details of the user but the problem is that the avatar is not being displayed properly if I inject it on its src.

Socialite returns an object wherein I could use it as $facebookDetails->getAvatar() in which returns a value of like this https://graph.facebook.com/v2.6/123456789/picture?type=normal

If I echo this value in the image src, it would look like this.

<img src="https://graph.facebook.com/v2.6/123456789/picture?type=normal" />

It seems that this is not the actual URL of the image since when I enter this on the browser, it redirects me to the "actual" image and displays the image.

How could I display the image on the img tag to display the actual image?

like image 365
basagabi Avatar asked Oct 21 '16 21:10

basagabi


1 Answers

Simply fetch the data using file_get_contents function and process the retrieved data.

In Controller

use File; 

$fileContents = file_get_contents($user->getAvatar());
File::put(public_path() . '/uploads/profile/' . $user->getId() . ".jpg", $fileContents);

//To show picture 
$picture = public_path('uploads/profile/' . $user->getId() . ".jpg");
like image 57
Nadeem0035 Avatar answered Sep 28 '22 17:09

Nadeem0035