Hello everyone,
Currently I’m developing a twitter video uploader with ruby. I’ve successfully uploaded images, but never got a video to upload correctly. From my understanding, to start a video upload, you’d post to:
url_upload = "https://upload.twitter.com/1.1/media/upload.json"
and give the parameters: command, media_type, and total_bytes.
response = HTTP.auth(twitter_header_oauth_video).post(url_upload, :body => 'command=INIT&media_type=video/mp4&total_bytes=4430752')
but most times I get this response:
{"errors":[{"code":38,"message":"media parameter is missing."}]}
I believe I’m doing OAuth correctly, because I don’t get errors related to that.
Am I going about this the correct way?
Or has anyone used HTTParty or HTTP etc… to upload a video to twitter and wouldn’t mind sharing an example? I’ve seen the twurl examples, but I can’t use twurl for my application.
Thanks
SOLUTION
oauth_params = {
:command => "INIT",
:total_bytes => '4430752',
:media_type => "video/mp4",
:oauth_consumer_key => TWITTER_CONSUMER_ID,
:oauth_nonce => nonce,
:oauth_signature_method => "HMAC-SHA1",
:oauth_timestamp => unix_epoch,
:oauth_token => twitter_user.access_token,
:oauth_version => "1.0"
}
oauth_signature_video = create_oauth_signature(twitter_user, http_method, url_upload, oauth_params)
twitter_header_oauth_video = create_oauth_header(twitter_user, nonce, unix_epoch, oauth_signature_video)
body_params_video_init = {
:command => "INIT",
:total_bytes => '4430752',
:media_type => "video/mp4"
}
response = HTTParty.post(url_upload, :headers => {"Authorization" => twitter_header_oauth_video}, :body => body_params_video_init)
response:
{"media_id"=>669242781429202944, "media_id_string"=>"669242781429202944", "expires_after_secs"=>86399}
The confusion is in which parameters are actually being calculated in the OAuth signature. I thought only the oauth_* params were used in calculating this, but no, apparently all parameters in this case.