php_nub_qq
php_nub_qq

Reputation: 16017

Get user id from facebook with Laravel 5 Socialite

New guy here, I'm trying to get a facebook user id so I can display a link to their profile on my site, however with laravel socialite I get some id that is not the profile id, I don't realy know what it is, here is my setup, pretty basic stuff

public function getFbredirect() {
    return Socialite::driver('facebook')->redirect();
}

public function getFbredirectback() {
    $user = Socialite::driver('facebook')->user();

    Session::set('fbid', $user); // stands for fb identity

    return redirect(Session::has('backto') ? Session::get('backto') : '/');
}

Then when I dd(Session::get('fbid') I get this object

enter image description here

As you can see there is an id but it is not the id I expect, the profile id I expect starts with 1, the one I get starts with 9.

So the question is how can I get the user's profile id?

Upvotes: 0

Views: 2134

Answers (1)

andyrandy
andyrandy

Reputation: 73984

It is the correct ID, but it´s an "App Scoped ID" since v2.0 of the Graph API. You can´t use the global/real ID anymore, but you don´t need it anyway. Here´s more information: https://developers.facebook.com/docs/apps/upgrading#upgrading_v2_0_user_ids

Linking to the user profile works exactly the same way: https://www.facebook.com/[app-scoped-id]

Upvotes: 1

Related Questions