## Gem file add this one
gem 'omniauth-twitter'
##config/initializers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, "CONSUMER_KEY", "CONSUMER_SECRET"
end
####Getting the twitter omniauth data
twitter_omniauth = request.env['omniauth.auth']
{
:provider => "twitter",
:uid => "123456",
:info => {
:nickname => "chinna",
:name => "Chinna",
:location => "Bangalore, India",
:image => "http://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png",
:description => "a very normal guy.",
:urls => {
:Website => nil,
:Twitter => "https://twitter.com/chinna"
}
},
:credentials => {
:token => "a1b2c3d4...", # The OAuth 2.0 access token
:secret => "abcdef1234"
},
:extra => {
:access_token => "", # An OAuth::AccessToken object
:raw_info => {
:name => "chinna",
:listed_count => 0,
:profile_sidebar_border_color => "181A1E",
:url => nil,
:lang => "en",
:statuses_count => 129,
:profile_image_url => "http://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png",
:profile_background_image_url_https => "https://twimg0-a.akamaihd.net/profile_background_images/229171796/pattern_036.gif",
:location => "chinna, India",
:time_zone => "Bangalore",
:follow_request_sent => false,
:id => 123456,
:profile_background_tile => true,
:profile_sidebar_fill_color => "666666",
:followers_count => 1,
:default_profile_image => false,
:screen_name => "",
:following => false,
:utc_offset => -3600,
:verified => false,
:favourites_count => 0,
:profile_background_color => "1A1B1F",
:is_translator => false,
:friends_count => 1,
:notifications => false,
:geo_enabled => true,
:profile_background_image_url => "http://twimg0-a.akamaihd.net/profile_background_images/229171796/pattern_036.gif",
:protected => false,
:description => "a very normal guy.",
:profile_link_color => "2FC2EF",
:created_at => "Thu Jul 4 00:00:00 +0000 2013",
:id_str => "123456",
:profile_image_url_https => "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png",
:default_profile => false,
:profile_use_background_image => false,
:entities => {
:description => {
:urls => []
}
},
:profile_text_color => "666666",
:contributors_enabled => false
}
}
}
###Getting twitter friends list
friends= Twitter.friends("#{twitter_omniauth['uid']}".to_i).attrs[:users]
##Getting twitter follwers list
followers= Twitter.followers("#{twitter_omniauth['uid']}".to_i).attrs[:users]
###get the raw information of the twitter data
@twitter_raw_data = twitter_omniauth.extra.raw_info
gem 'omniauth-twitter'
##config/initializers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :twitter, "CONSUMER_KEY", "CONSUMER_SECRET"
end
####Getting the twitter omniauth data
twitter_omniauth = request.env['omniauth.auth']
{
:provider => "twitter",
:uid => "123456",
:info => {
:nickname => "chinna",
:name => "Chinna",
:location => "Bangalore, India",
:image => "http://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png",
:description => "a very normal guy.",
:urls => {
:Website => nil,
:Twitter => "https://twitter.com/chinna"
}
},
:credentials => {
:token => "a1b2c3d4...", # The OAuth 2.0 access token
:secret => "abcdef1234"
},
:extra => {
:access_token => "", # An OAuth::AccessToken object
:raw_info => {
:name => "chinna",
:listed_count => 0,
:profile_sidebar_border_color => "181A1E",
:url => nil,
:lang => "en",
:statuses_count => 129,
:profile_image_url => "http://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png",
:profile_background_image_url_https => "https://twimg0-a.akamaihd.net/profile_background_images/229171796/pattern_036.gif",
:location => "chinna, India",
:time_zone => "Bangalore",
:follow_request_sent => false,
:id => 123456,
:profile_background_tile => true,
:profile_sidebar_fill_color => "666666",
:followers_count => 1,
:default_profile_image => false,
:screen_name => "",
:following => false,
:utc_offset => -3600,
:verified => false,
:favourites_count => 0,
:profile_background_color => "1A1B1F",
:is_translator => false,
:friends_count => 1,
:notifications => false,
:geo_enabled => true,
:profile_background_image_url => "http://twimg0-a.akamaihd.net/profile_background_images/229171796/pattern_036.gif",
:protected => false,
:description => "a very normal guy.",
:profile_link_color => "2FC2EF",
:created_at => "Thu Jul 4 00:00:00 +0000 2013",
:id_str => "123456",
:profile_image_url_https => "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png",
:default_profile => false,
:profile_use_background_image => false,
:entities => {
:description => {
:urls => []
}
},
:profile_text_color => "666666",
:contributors_enabled => false
}
}
}
###Getting twitter friends list
friends= Twitter.friends("#{twitter_omniauth['uid']}".to_i).attrs[:users]
##Getting twitter follwers list
followers= Twitter.followers("#{twitter_omniauth['uid']}".to_i).attrs[:users]
###get the raw information of the twitter data
@twitter_raw_data = twitter_omniauth.extra.raw_info
Comments
Post a Comment