我将 Laravel 5.2 与 Socialite 一起使用。我能够提取用户的详细信息,但问题是如果我将头像注入(inject)到它的 src
中,则头像无法正确显示。
Socialite 返回一个对象,我可以在其中将其用作 $facebookDetails->getAvatar()
,其中返回一个类似 https://graph.facebook.com/v2.6/123456789/picture?type=normal
的值
如果我在图像 src
中回显这个值,它看起来像这样。
<img src="https://graph.facebook.com/v2.6/123456789/picture?type=normal" />
这似乎不是图像的实际 URL,因为当我在浏览器中输入它时,它会将我重定向到“实际”图像并显示图像。
如何在 img
标签上显示图像以显示实际图像?
最佳答案
只需使用 file_get_contents
函数获取数据并处理检索到的数据。
在 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");
关于php - Laravel 社交名媛 facebook 头像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40185781/