ruby-on-railsrubytwittertwitter-followsocial-network-friendship

How to get Ruby twitter to check friendship relationship


How do I make the friendship method work with the Twitter gem to check the relationships of users friends and or followers? The error says there are no parameters.

My code is:

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

EDIT :

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

Response:

#<Twitter::Relationship:0x007f88c1e58de0>

How can I extract the hash response to a readable output i.e. boolean to let me know what its suppose to be saying?


Solution

  • http://www.rubydoc.info/github/sferik/twitter/master/Twitter/REST/FriendsAndFollowers:friendship

    According to the documentation, it appears you're using the wrong method and passing incorrect parameters. The parameters are not a hash with the keys 'source' and 'target', they're simply two strings representing the source and target users.

    Calling Twitter::REST::FriendsAndFollowers.friendship('user1', 'user2') should return a Twitter::Relationship object containing information about the relationship between the two users.

    EDIT

    Calling client.friendship?('user1', 'user2') returns true if user1 follows user2, and false is otherwise.