Skip to content

Instantly share code, notes, and snippets.

@digidigo
Created December 15, 2011 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digidigo/1483411 to your computer and use it in GitHub Desktop.
Save digidigo/1483411 to your computer and use it in GitHub Desktop.
True Twitter Friends
# get union of friends and followers
def true_twitter_friends
return [] unless self.twitter_token && twitter_token.length > 3
return @twitter_friends_cache if @twitter_friends_cache
ids = []
if( !self.twitter_token.blank? )
friends = []
followers = []
Twitter.configure do |config|
config.consumer_key = TWITTER_KEY
config.consumer_secret = TWITTER_SECRET
config.oauth_token = self.twitter_token
config.oauth_token_secret = self.twitter_secret
end
client = Twitter::Client.new
begin
client.friend_ids.collection.each do |id|
friends << id
end
client.follower_ids.collection.each do |id|
followers << id
end
ids = friends.sort & followers.sort
rescue Exception => e
Rails.logger.error("Unable to get twitter friends #{e.message}")
end
end
@twitter_friends_cache = ids
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment