Skip to content

Instantly share code, notes, and snippets.

@kimihito
Created December 5, 2012 17:01
Show Gist options
  • Save kimihito/4217459 to your computer and use it in GitHub Desktop.
Save kimihito/4217459 to your computer and use it in GitHub Desktop.
Upload profile image (using image url) on Twitter. (Thanks a lot, @hanachin_)
#!/usr/bin/env ruby
#-*- coding: utf-8 -*-
require 'twitter'
require 'open-uri'
require 'tempfile'
Twitter.configure do |config|
config.consumer_key = YOUR_CONSUMER_KEY
config.consumer_secret = YOUR_CONSUMER_SECRET
config.oauth_token = YOUR_OAUTH_TOKEN
config.oauth_token_secret = YOUR_TOKEN_SECRET
end
img_url = "http://a0.twimg.com/profile_images/2935155837/1d457cc612260bbd7ace398083330886_normal.jpeg"
img = open(img_url)
#make tmp file.
tempfile = Tempfile.open('icon'){|file| file.write img.read; file}
#update
Twitter.update_profile_image(open(tempfile.path))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment