People you're following on Twitter using twitter-auth

Language: Ruby

# using the Twitter base app mentioned here: http://blog.railsrumble.com/2009/7/23/this-bird-s-ready-to-rumble

class User < TwitterAuth::GenericUser

  def twitter_following_ids # ids of users followed on twitter
    ids = []
    pages = (self.friends_count/100.0).ceil
    1.upto(pages) do |page|
      results = twitter.get("/statuses/friends?page=#{page}")
      results.each do |result|
        ids << result['id'].to_s
      end
    end
    ids
  rescue
    nil
  end

end
Reveal More
Added over 2 years ago by Costco_normal trevorturk

Refactorings

Re: People you're following on Twitter using twitter-auth

Refactoring of: People you're following on Twitter using twitter-auth

Language: Ruby

# using the Twitter base app mentioned here: http://blog.railsrumble.com/2009/7/23/this-bird-s-ready-to-rumble

class User < TwitterAuth::GenericUser

  def twitter_following_ids # ids of users followed on twitter
    twitter.get("/friends/ids")
    rescue
      nil
    end
  end

end

# Using /friends/ids API, no pagination necessary and just one call returns all friends' ids
Reveal More
Added over 2 years ago by Default_profile_6_normal nanotechno

Re: Re: People you're following on Twitter using twitter-auth

Refactoring of: People you're following on Twitter using twitter-auth

Language: Ruby

# Thanks for the tip! I had to do the following for this app, but it works much better now - much, much faster!

class User < TwitterAuth::GenericUser

  def twitter_following_ids # ids of users followed on twitter
    twitter.get("/friends/ids").collect! { |id| id.to_s }
  rescue
    nil
  end

end
Reveal More
Added over 2 years ago by Costco_normal trevorturk