2011-12-04 7 views
0

twitterメールを使用してdevise :omniauthableを利用することはできますか?twitterの電子メールを作成する

私はFacebookのメールを取得し、この方法でユーザーを作成することができます。

def self.find_for_facebook_oauth(access_token, signed_in_resource=nil) 
    data = access_token['extra']['user_hash'] 
    if user = User.find_by_email(data["email"]) 
    user 
    else # Create a user with a stub password. 
    User.create!(:email => data["email"], :password => Devise.friendly_token[0,20]) 
    end 
end 

コントローラ:私はuser_iduidを持って入ってくるのparamsでTwitterのOAuthのた​​めに、このようなものを使用している場合

class OmniauthCallbacksController < Devise::OmniauthCallbacksController 

    def facebook 
    @user = User.find_for_facebook_oauth(env["omniauth.auth"], current_user) 
    if @user.persisted? 
     flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Facebook" 
     sign_in_and_redirect @user, :event => :authentication 
    else 
     session["devise.facebook_data"] = env["omniauth.auth"] 
     redirect_to new_user_registration_url 
    end 
    end 

    def twitter 
    @user = User.find_for_twitter_oauth(env['omniauth.auth']) 

    if @user.persisted? 
     flash[:notice] = I18n.t 'devise.omniauth_callbacks.success', :kind => 'Twitter' 
     sign_in_and_redirect @user, :event => :authentication 
    else 
     flash[:notice] = I18n.t 'devise.omniauth_callbacks.failure', :kind => 'Twitter', :reason => 'User not found' 
     redirect_to new_user_session_path 
    end 
    end 
end 

credentialssecretなどですが、メールはありません。この方法で入手できますか?私はユーザーテーブルの新しいフィールドを追加したり、ユーザーID、oauth prowiders、およびoauth IDを持つ新しいテーブルを追加することは望ましくありません。

Mbもっときれいなやり方warden戦略​​with twitter

答えて

2

Twitter API はありませんは返信メールですので、それをどのように処理するか

関連する問題