0

I've set up my rails 3 app to use omniauth-facebook, everything works fine but when I look at the omniauth hash as yaml there is no 'nickname' field, I can get the 'name' and 'email' but my validations fail to create a user because I can't grab the nickname for my app's username requirement.

I've double checked my facebook account, under "Settings", and my username is displayed. ANy ideas why this would be happening? Thanks for the help.

Here is an example of my omniauth hash, i've placed 'X' for privacy reason:

--- !ruby/hash:OmniAuth::AuthHash
provider: facebook
uid: 'XXXXXXXXXXXXX'
info: !ruby/hash:OmniAuth::AuthHash::InfoHash
  email: XXXX@XXXX.XX
  name: XXXX XXXX
  first_name: XXXX
  last_name: XXXX
  image: http://graph.facebook.com/XXXXXXXXXXXXX/picture
  urls: !ruby/hash:OmniAuth::AuthHash
    Facebook: https://www.facebook.com/app_scoped_user_id/XXXXXXXXXXXXX/
  verified: true
credentials: !ruby/hash:OmniAuth::AuthHash
  token: ACCESS_TOKEN
  expires_at: 1406357169
  expires: true
extra: !ruby/hash:OmniAuth::AuthHash
  raw_info: !ruby/hash:OmniAuth::AuthHash
    id: 'XXXXXXXXXXXXXXX'
    email: XXXX@XXXX.XX
    first_name: XXXX
    gender: male
    last_name: XXXX
    link: https://www.facebook.com/app_scoped_user_id/XXXXXXXXXXXXX/
    locale: en_US
    name: XXXX XXXX
    timezone: 7
    updated_time: '2014-05-07T00:58:12+0000'
    verified: true
user1009762
  • 199
  • 3
  • 11

2 Answers2

1

There's no field nickname, do you mean username? If so it's no longer available if you use the Graph API v2.0.

References:

Tobi
  • 31,405
  • 8
  • 58
  • 90
  • sorry, yes it's not showing the username. I edited the question, on the omniauth-facebook gem it shows as nickname. Is this depreciated and not longer supported by facebook? is there a way to retrieve the username from facebook? under my facebook App settings it says my username will be public along with my other profile info to all apps I authorize – user1009762 May 27 '14 at 12:49
  • my app was created today on facebook so I think it will be using the API v2.0, which is stated here: https://developers.facebook.com/docs/apps/versions – user1009762 May 27 '14 at 12:52
  • It's deprecated, see the link you just referenced: `/me/username is no longer available.` – Tobi May 27 '14 at 12:52
  • this link says that the username should be available to anyone who uses the graph API if the user has chosen to make it public, which my testing facebook has, why would it not be included in the omniauth hash? https://www.facebook.com/about/privacy/your-info#public-info – user1009762 May 27 '14 at 12:58
  • Because I guess the link you pasted is outdated and has nothing to do with the Graph API? I guess you can edit `omniauth-facebook` and remove this line: https://github.com/mkdynamic/omniauth-facebook/blob/master/lib/omniauth/strategies/facebook.rb#L36 – Tobi May 27 '14 at 13:01
  • hehe okay, thank you for the help. As a sidenote, would you know why facebook would choose to not include the username anymore? I don't understand it, when the email (more sensitive information) is still available? Also the hash includes a URL to your facebook page but with the scoped_user_id number, when copy and pasted into a browser it changes into facebook.com/username. Would there be a ruby way to decode this ID into the username? – user1009762 May 27 '14 at 13:06
  • I guess it's because they want to remove unique references to the individual user. The removed the global `user_id`, and `username` is another global identifier. So I guess it's constistent... – Tobi May 27 '14 at 13:12
0

I know this is an old question. Since facebook now does not support fetching username at time of login, a workaround for getting user name would be, to call GraphRequest.newMeRequest() from the onSuccess() method of facebook login button

Rusheel Jain
  • 843
  • 6
  • 20