authlogic_oauth
authlogic_oauth copied to clipboard
Getting twitter username after successful auth / registration
Hi everyone.
Is it possible to get twitter username / user id from authlogic_oauth after twitter authentication?
I see twitter user id in the live example, but i still didn't get it to work in my application, i get NO additional information at all and no information on twtiiter_uid user column at all.
How you guys get additional user information from oauth?
In order to interact with twitter you need to use the oauth access token. But they make that a private method so to get at it you need to add an extra method to your user model.
class User < ActiveRecord::Base
acts_as_authentic
def twitter_profile
@twitter_profile ||= JSON.parse(access_token.get('/account/verify_credentials.json').body)
end
end
That will give you a hash with all sorts of info about the user. Now since it is just parsing the JSON twitter returns you need to use strings for the key. But to get the twitter username you would do something like this.
@user.twitter_profile['screen_name']
Hope that helps.
Follow Me: @JoshRobinson