-
-
Save shenzhaoyan/1085935 to your computer and use it in GitHub Desktop.
twitter config
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
Twitter.configure do |config| | |
# config.gateway = "http://#{self.apigee_twitter_api_endpoint}" | |
config.consumer_key = self.twitter_key | |
config.consumer_secret= self.twitter_secret | |
config.oauth_token = authentication.token | |
config.oauth_token_secret = authentication.secret | |
end | |
user.set_is_working! true, 1,"Retrieving followers and friends!",false | |
#log "Key: #{self.twitter_key} against http://#{self.apigee_twitter_api_endpoint}" | |
log "Retrieving friends for user #{self.user_name}" | |
client = Twitter::Client.new | |
max_tries = 50 # e.g. limit = 5000 | |
cursor = -1 | |
total_user_count= 0 | |
begin | |
max_tries = max_tries - 1 | |
# client | |
hashie = client.friends(:cursor => cursor) | |
cursor = hashie.next_cursor | |
log "Request results in #{hashie.users.count} users" | |
hashie.users.each do |x| | |
begin | |
p = SocialPerson.create_or_update_social_person!('twitter', | |
x['screen_name'], | |
x['name'], | |
x['screen_name'], | |
x['description'], | |
x['profile_image_url'], | |
x['location']) | |
c = SocialConnection.get_or_create!(user,p) | |
rescue Exception => e | |
log "Oops #{e.message}" | |
# TODO: LOG THIS AS AN IMPORT ERROR FOR GECKOBOARD | |
end | |
# create relationship here | |
end | |
total_user_count =total_user_count +hashie.users.count | |
user.set_is_working! true, 50,"Fetching social_persons. #{total_user_count} social_persons so far.",false | |
log "Fetched #{hashie.users.count} social_persons." | |
end until max_tries < 0 || cursor == nil || cursor == 0 | |
#user.user_status.is_new_user = true | |
user.set_is_working false, 100,"Setup completed successfully!",false | |
user.user_status.is_setup_complete = true | |
user.save! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment