获取经过身份验证的用户facebook socialite laravel的上传图片

时间:2018-06-27 06:38:12

标签: php facebook facebook-graph-api laravel-5 laravel-socialite

我正在使用laravel 5.4.36版,并且正在使用Laravel Sociallite plugin将用户与Facebook连接起来。

我想按照document中的建议获取已登录用户的上载图片。可通过User对象上的照片边缘使用该图片。

    [X,Y] = meshgrid(1:0.5:10,1:20);
Z = sin(X) + cos(Y);
surf(X,Y,Z)
xlabel('Non dimensional stiffness \rightarrow','FontSize',13.5, 'FontName','Rockwell','Rotation',0);
ylabel('Non dimensional mass  \rightarrow','FontSize',13.5,'FontName','Rockwell','Rotation',0);
zlabel('Dimensional frequencies  \rightarrow','FontSize',13.5,'FontName','Rockwell');

在上面的代码中,我已请求

  

用户照片作为范围,照片作为字段

enter image description here

我的回调函数是

public function redirect()
{
    //  return Socialite::driver('facebook')->redirect();
     return Socialite::driver('facebook')->fields([
        'first_name', 'last_name', 'email', 'gender', 'birthday','location','hometown','age_range','friends','posts','photos'
    ])->scopes([
        'email', 'user_birthday','user_gender','user_location','user_hometown',
        'user_age_range','user_friends','user_link','user_photos','user_posts',
        'user_tagged_places','user_videos','user_likes',
    ])->redirect();
}

在我仍然要求照片的地方,我仍然无法获得照片的年龄

public function callback(SocialFacebookAccountService $service)
{
    $user = $service->createOrGetUser(Socialite::driver('facebook')->fields([
        'name', 'email', 'birthday','gender','location','hometown','age_range','friends','link',
        'photos','posts','tagged_places','videos','likes',
    ])->user());
    auth()->login($user);
    return redirect()->to('/home');
}

namespace App\Services; use App\SocialFacebookAccount; use App\User; use Laravel\Socialite\Contracts\User as ProviderUser; use File; class SocialFacebookAccountService { public function createOrGetUser(ProviderUser $providerUser) { echo "<pre>"; print_r($providerUser);die; $account = SocialFacebookAccount::whereProvider('facebook') ->whereProviderUserId($providerUser->getId()) ->first(); if ($account) { return $account->user; } else { $account = new SocialFacebookAccount([ 'provider_user_id' => $providerUser->getId(), 'provider' => 'facebook' ]); $user = User::whereEmail($providerUser->getEmail())->first(); // echo "<pre>";print_r($user);die; if(!empty($providerUser->getAvatar())){ $fileContents = file_get_contents($providerUser->getAvatar()); File::put(public_path() . '/uploads/profile/' . $providerUser->getId() . ".jpg", $fileContents); } $imageUrl = $providerUser->getId() . ".jpg"; // echo "<pre>";print_r($providerUser->user);die; if (!$user) { $user = User::create([ 'email' => $providerUser->getEmail(), 'name' => $providerUser->getName(), 'password' => md5(rand(1,10000)), 'avatar'=> $imageUrl, 'birthday' => $providerUser->user['birthday'], 'gender' => $providerUser->user['gender'], 'age_range' =>$providerUser->user['age_range']['min'], 'total_friends'=>$providerUser->user['friends']['summary']['total_count'], 'profile_link'=>$providerUser->user['link'], ]); } $account->user()->associate($user); $account->save(); return $user; } } } 函数的开头具有打印功能,但是我仍然无法在用户对象下获得照片的年龄。

请提出任何建议。

0 个答案:

没有答案