Bob
Bob

Reputation: 831

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.

Upvotes: 3

Views: 2078

Answers (3)

mbenegas
mbenegas

Reputation: 481

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

Upvotes: 5

BlueSix
BlueSix

Reputation: 126

For those coming here after 1 May 2014, Test Apps now default to the v2 API, which will cause problems if your app was built using v1. See last post in the FAQ here https://developers.facebook.com/docs/apps/test-apps

Upvotes: 0

Mike
Mike

Reputation: 783

Not all facebook users have usernames but they ALL have user ids. (e.g. it's optional to have an alphanumeric username, just gives easy access - facebook.com/johnsmith or smth)

Your best bet is to store the ID (the 10 or so digit number) and if you're storing names, perhaps store their first name like stackoverflow does.

Upvotes: 0

Related Questions