Check Twitter user relationship created_at?

117 Views Asked by At

I'm stuck trying to extract the Twitter hash and can't seem to find out how to get the friendship attributes?

My code:

require 'twitter'
require 'rubygems'

client = Twitter::REST::Client.new do |config|
  config.consumer_key = "..."
  config.consumer_secret = "..."
  config.access_token = "..."
  config.access_token_secret = "..."
end

puts client.friendship('user1','user2').to_s

Response:

#<Twitter::Relationship:0x007f88c1e58de0>

Is there a way to extract the info so I can retrieve the hash array of info on the relationship? i.e. like when the friendship was created?

1

There are 1 best solutions below

0
Pramod Shinde On

I think you cannot find created_at but you get other attributes

You can use direct attribute name like

data = client.friendship('user1','user2')
data.source.screen_name # user1 

If not convert it to JSON like

data = client.friendship('user1','user2').as_json
handle = data["target"]["screen_name"] # user2

Sample response after as_json

{"source"=>
 {
  "id"=>7697764211,
  "id_str"=>"7697764211",
  "screen_name"=>"user1",
  "following"=>true,
  "followed_by"=>false,
  "following_received"=>nil,
  "following_requested"=>nil,
  "notifications_enabled"=>nil,
  "can_dm"=>false,
  "blocking"=>nil,
  "blocked_by"=>nil,
  "muting"=>nil,
  "want_retweets"=>nil,
  "all_replies"=>nil,
  "marked_spam"=>nil},
"target"=>
 { "id"=>2053615711,
   "id_str"=>"2053615711",
   "screen_name"=>"use2",
   "following"=>false,
   "followed_by"=>true,
   "following_received"=>nil,
   "following_requested"=>nil
 }}