socialite: getAvatar() doesn't return the Facebook avatar

  • Socialite Version: v5.0.1
  • Laravel Version: v8.4.0
  • PHP Version: v7.3.11
  • Database Driver & Version: MySQL

Description:

The getAvatar() method doesn’t return the publicly available profile image URL. It assumes size/type = normal, which is fine, but it lacks the access token, thus returning the default Facebook “no profile image” image.

If one is to retrieve the avatar, one must append &access_token=XXXXXXXX... to the getAvatar(), which is not at all obvious. Shouldn’t the getAvatar() return the public image by default, or at least have the boolean parameter to choose this?

Steps To Reproduce:

Just call the Socialite::driver('facebook')->user()->getAvatar() in the handleProviderCallback.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 8
  • Comments: 16 (6 by maintainers)

Most upvoted comments

@precompiled could you resolve it? I’m still facing this issue.

@galkrisztina As mentioned originally, I’ve just appended the access_token to the query. Like so:

$fbUser = Socialite::driver('facebook')->user(); 
$img = $fbUser->avatar_original . "&access_token={$fbUser->token}

Hopefully this won’t be needed once the fix comes. 😃

It works just fine for me.

In addition, there also could be an option for the ->getAvatar() method to choose an image size, because that tiny image is absolutely useless.

Steps To Reproduce:

Socialite::driver('facebook')->user()->getAvatar(1920) will create: https://graph.facebook.com/v3.3/ID/picture?width=SIZE&access_token=TOKEN

we can use this code to get the redirect url provided by getUrl with token

            $url = $user->getAvatar() . '&access_token=' . $user->token;
            $ch = curl_init();

            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);

            $res = curl_exec($ch);
            $redirectedUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);

@precompiled thanks for that post btw. Would have helped if you posted that in the original issue. I didn’t know they were getting deprecated.

@precompiled @ptlevi @galkrisztina instead of downvoting my reply, please provide more accurate steps to reproduce. I tested with the above and the avatar urls were publicly accessible for me.