Created
December 15, 2011 23:11
-
-
Save digidigo/1483411 to your computer and use it in GitHub Desktop.
True Twitter Friends
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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