get first_name and last_name fields from facebook omniauth

后端 未结 3 751
慢半拍i
慢半拍i 2021-02-15 15:58

I am now implementing omniauth feature into my app. Everything works fine except that i cant get the first and last name from the facebook. Here is my model code.



        
3条回答
  •  不知归路
    2021-02-15 16:17

    From checking the Facebook docs, the first_name and last_name fields are both part of the public profile so your permissions should be fine.

    No idea if this would work (in fact, I would kind of hope it doesn't), but in the implementation we've got working in production at the moment we're using Hash accessors instead of methods. So:

    new(
      first_name: oauth_data["info"]["first_name"],                  
      last_name:  oauth_data["info"]["last_name"],     
      ...
    

    Given your email etc fields are getting set correctly, I'd be surprised if trying that works, but it might be worth a shot.

    Failing that, have you got any validations or before_create callbacks which could be interfering somehow?

提交回复
热议问题