Created
August 17, 2010 05:33
-
-
Save gotwalt/528586 to your computer and use it in GitHub Desktop.
Posting to twitpic in Ruby using oauth echo
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
require "nestful" | |
require "roauth" | |
def upload(path_to_file) | |
twitpic_key = "my_twitpic_api_key" | |
oauth_url = "https://api.twitter.com/1/account/verify_credentials.json" | |
oauth = { | |
:access_key => "account_access_key", | |
:access_secret => "account_access_secret", | |
:consumer_key => "application_key", | |
:consumer_secret => "application_secret" | |
} | |
oauth_result = ::ROAuth.header(oauth, oauth_url, {}) | |
headers = { | |
"X-Auth-Service-Provider" => oauth_url, | |
"X-Verify-Credentials-Authorization" => oauth_result | |
} | |
params = { | |
:media => File.open(path_to_file), | |
:key => twitpic_key | |
} | |
result = Nestful.post(endpoint_url, :format => :multipart, :headers => headers, :params => params) | |
JSON.parse(result) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: this code requires http://github.com/maccman/roauth and http://github.com/maccman/nestful to work.