Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook getUser returns wrong ID

I have an problem in my app. The only thing I need from a user is there facebook id. After they log onto facebook they are redirected back to my app and I can get the userID with $facebook->getUser(). This works fine except when the user has chosen a username on facebook. Then I get a really weird long ID that is different from the userid.

To clarify, let's say I ask the userid from a user that hasn't set a username, I get for example the id: 1234567891. When a user has set a username, I get an ID like: 100002339295322.

Anyone maby knows how I can solve this ?

If you need code samples of how I do things, I do them as told on the facebook developers site: http://developers.facebook.com .

With friendly greetings, Bob

PS: I use the CodeIgniter framework and the official facebook php sdk

*/// EDIT \*

The problem is solved. Apparently it had something to do with the datatype I used for the field. I changed it from int to varchar and now everything is working.

like image 432
Bob Avatar asked Jun 08 '26 04:06

Bob


1 Answers

I had a similar problem, and found out that after v2.0 API user_id is app scoped. I had two user_id for the same user's profile but different application, and both are valid for their respective app.

You can reach the user profile with

http://facebook.com/app_scoped_user_id/<USER_ID>

You may also query the graph api, using the app token and the app scoped user id.

Ref.: https://developers.facebook.com/docs/apps/upgrading/#upgrading_v2_0_user_ids

like image 52
mbenegas Avatar answered Jun 10 '26 19:06

mbenegas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!