Facebook getUser returns wrong ID Facebook getUser returns wrong ID codeigniter codeigniter

Facebook getUser returns wrong ID


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


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.


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