2016-03-30 8 views
0

タイムゾーンを除くサインアップ時に、user.rbのすべてが正しく渡されています。omniauthでfacebookからタイムゾーンを取得するには?

2016-03-30T20:13:38.083469+00:00 app[web.1]: NoMethodError (undefined method `timezone=' for #<User:0x007fdd2976e338>): 
2016-03-30T20:13:38.083470+00:00 app[web.1]: app/models/user.rb:72:in `block in from_omniauth' 
2016-03-30T20:13:38.083471+00:00 app[web.1]: app/models/user.rb:66:in `tap' 
2016-03-30T20:13:38.083471+00:00 app[web.1]: app/models/user.rb:66:in `from_omniauth' 
2016-03-30T20:13:38.083472+00:00 app[web.1]: app/controllers/sessions_controller.rb:7:in `facebook' 

user.rbに

def self.from_omniauth(auth) 
    # Sets 60 day auth token 
    oauth = Koala::Facebook::OAuth.new("1540371223342976229929", "ee917abf2e8f1c98274cd323fa1234ebb1346f4") # Fake Numbers 
    new_access_info = oauth.exchange_access_token_info auth.credentials.token 

    new_access_token = new_access_info["access_token"] 
    new_access_expires_at = DateTime.now + new_access_info["expires"].to_i.seconds 

    where(provider: auth.provider, uid: auth.uid).first_or_initialize.tap do |user| 
     user.provider = auth.provider 
     user.image = auth.info.image 
     user.uid = auth.uid 
     user.name = auth.info.first_name 
     user.last_name = auth.info.last_name 
     user.timezone = auth.info.timezone 
     user.email = auth.info.email unless user.email.present? 
     user.oauth_token = new_access_token # auth.credentials.token <- your old token. Not needed anymore. 
     user.oauth_expires_at = Time.at(auth.credentials.expires_at) 
     user.password = (0...8).map { (65 + rand(26)).chr }.join 
     user.activated = true 
     user.save! 
    end 
    end 

のconfig/omniauth.rb

を:私は、ユーザーがサインインしようとすると、この エラーを取得していますなぜ私は把握することはできません
Rails.application.config.middleware.use OmniAuth::Builder do 
    provider :facebook, "1540324372976229929", "ee917abf2e8423f1c98274cdfa234234ebb1346f4", {info_fields: 'email, first_name, last_name, timezone'} 
end 

t.float "timezone"Facebook docs say秒のタイムゾーンはfloatにする必要があります。

+0

タイムゾーンが正しく保存されていますか? Facebookが提供する[auth hash](https://github.com/mkdynamic/omniauth-facebook#auth-hash)からは、ハッシュ構造が異なるように見えます。 - > 'auth.extra.raw_info.timezone' –

+0

タイムゾーンはまったく保存されません。私が言及したエラーを得る。私はそれを試してみて、それがどのように行くか教えてください:] @JustinLicata –

+0

しかし、そのエラーはまた、あなたのユーザーテーブルにタイムゾーンの列がないように見えます。 –

答えて

1

omniauthが提供する認証ハッシュが、使用しているものとは少し異なる構造を持っているようです。これを試して。

user.timezone = auth.extra.raw_info.timezone 

Here is the hash structureこれはFacebook omniauthで利用可能です。

+0

あなたが参加したい場合、ここで会話を続けました:] http://stackoverflow.com/questions/36319711/how-can-i-convert-float-number-to-timezone –

関連する問題