I am uploading large video to Twitter and getting erros
media = File.open('/home/geobeats/Downloads/test.mp4', 'rb')
segment_id = 0
bytes_sent = 0
access_token = Oauth::Twitter.new.access_token
resp_1 = access_token.post("https://upload.twitter.com/1.1/media/upload.json",
{command: 'INIT', media_type: 'video/mp4', total_bytes: media.size, media_category: 'tweet_video'})
while bytes_sent < media.size
chunk = media.read(4*1024*1024).encode('utf-8', 'binary', invalid: :replace, undef: :replace, replace: '')
req = access_token.post("https://upload.twitter.com/1.1/media/upload.json",
{command: 'APPEND', media_id: JSON.parse(resp_1.body)['media_id'], segment_index: segment_id, media: chunk})
p req.body
segment_id = segment_id + 1
bytes_sent = media.tell
end
Every time it gives error at APPEND call
Aucun commentaire:
Enregistrer un commentaire