我正在尝试为通过Facebook登录的网站设置omniauth。问题是Facebook没有发送'信息'字段。
我为不同的环境设置了2个facebook应用程序。
对于一个应用,响应具有字段
#<OmniAuth::AuthHash credentials=#<OmniAuth::AuthHash expires=true expires_at=14
42913734 token="CAAU6NSaozowBANJoDeZCakDuUZAiIZBGQ5cmFYRTwQwo7SK2JK7uhcRK7WIadpp
zjKfict9pMASS2k9XJZBTgnI8WJvJA42er9Xj8nuoeLjbEQo8TKB7b5hVlsOwRs5kcPpOPwyUTUc0ekF
uu2w4ubNZBMXZBw5xjGkQwZBZA46fATGOvDXJSrWOOAiQteWnkSO9JkeZC2SfmZCQqcSR0zdV52"> ex
tra=#<OmniAuth::AuthHash raw_info=#<OmniAuth::AuthHash id="xxxxxxxxxx" na
me="xxxxxxx">> info=#<OmniAuth::AuthHash::InfoHash image="http://graph.facebo
ok.com/xxxxxxxxxxx/picture" name="xxxx"> provider="facebook" uid="xxxxxxxx">
在开发环境中,我得到了回复
#<OmniAuth::AuthHash credentials=#<OmniAuth::AuthHash expires=true expires_at=14
42912896 token="CAAPK1ZAgrDtEBAKKvcj4jGu6iaIxYYJV7LZCJ6MZCELZCgNyowkqPeB5kHBsVw4
ZBKoZCv4DD6my4s8qhO1hJyEFzcb1IpKt03ydzWORZCR3PCf1bw6A9jRudmcJn1N37WgqckmuKUj4k1y
qb3fcRpNPxAxx0asXJlaUJTcVR5wi0sRIOc9l3yFm6XyuMA464MBz5vt9AvNcVB9DAGm5kHr"> extra
=#<OmniAuth::AuthHash raw_info=#<OmniAuth::AuthHash email="xxxxx@yahoo.co.in"
first_name="xxxx" gender="male" id="xxxxx" last_name="xxxx" link="h
ttps://www.facebook.com/app_scoped_user_id/xxxx/" locale="en_US" na
me="xxxx" timezone=10 updated_time="2015-06-06T03:35:33+0000" verified=tru
e>> info=#<OmniAuth::AuthHash::InfoHash email="xxxxxxx" first_name="
xx" image="http://graph.facebook.com/xxx/picture" last_name="xxxxx" name="xxxxx" urls=#<OmniAuth::AuthHash Facebook="https://www.facebook.c
om/app_scoped_user_id/xxxxx/"> verified=true> provider="facebook" ui
d="xxxxxxxxxxxxxxxx">
我想知道它是否是应用级设置,因为两者的代码相同。应用方面唯一的区别是API v2.3,其他是2.4
答案 0 :(得分:8)
使用v2.3和v2.4时存在差异。
在您的config/initializers/devise.rb
文件或放置API密钥的任何位置,除了info_fields
之外,您还必须添加scope
,
例如
config.omniauth :facebook, APP["facebook_id"], APP["facebook_secret"],
:scope => 'email,public_profile', info_fields: 'email,name'