Twitter Chunked media upload

Hello,

Anyone has example for doing Chunked media upload to Twitter? It appears that it works quite different than basic post. Following Twitter documentation, I got that this kind of upload has to be done in 4 steps: INIT, APPEND, FINALIZE and CREATE TWEET with media.
Posting tweets works great with using CURL module, using CURL through Shell or using CURL examples from MBS package. Also, same things goes for image upload. When it comes to chunked media upload, I want to upload mp4 file which is 12 MB, I am unable to create proper signature and always get ‘‘Could not authenticate you’’ error.

Bellow is code for creating signature, which with some changes works for Post tweet.

dim HTTPmethod as String = "POST"
dim baseURL as String = "https://upload.twitter.com/1.1/media/upload.json"

dim params as String

params = EncodeURLComponent("command") + "=" + EncodeURLComponent("INIT")
params = params + "&" + EncodeURLComponent("media_type") + "=" + EncodeURLComponent("video/mp4")
params = params + "&" + EncodeURLComponent("oauth_consumer_key") + "=" + EncodeURLComponent(oauth_consumer_key) 
params = params + "&" + EncodeURLComponent("oauth_token") + "=" + EncodeURLComponent(oauth_access_token)
params = params + "&" + EncodeURLComponent("oauth_signature_method") + "=" + EncodeURLComponent("HMAC-SHA1")
params = params + "&" + EncodeURLComponent(oauth_timestamp) + "=" + EncodeURLComponent(oauth_timestamp)
params = params + "&" + EncodeURLComponent(oauth_nonce) + "=" + EncodeURLComponent(oauth_nonce)
params = params + "&" + EncodeURLComponent("oauth_version") + "=" + EncodeURLComponent("1.0")
params = params + "&" + EncodeURLComponent("total_bytes") + "=" + EncodeURLComponent("12118508")

dim signature_base_string as String = HTTPmethod + "&" + EncodeURLComponent(baseURL) + "&" + EncodeURLComponent(params)

dim str3 as String

//EncodeURLComponent(message)
str3 = EncodeURLComponent(oauth_consumer_secret)+"&"+EncodeURLComponent(oauth_access_token_secret)

Dim sha1class As New SHA1MBS
Dim hmacsha1 As String= sha1class.HMAC(str3,signature_base_string)
oauth_signature = EncodeBase64(hmacsha1)
oauth_signature = EncodeURLComponent(oauth_signature)

Does anyone has any idea or example how to create valid signature or has faster way to upload larger files to Twitter?

Thank you

The params string is already URL encoded, are you sure it needs to be re-encoded?

Well, I was just following Twitter documentation. It requires every param pair to be separately encoded and then complete string to be encoded.

Answering my own question.

Apparently, parameter marked as ‘‘optional’’ is actually required for INIT. Using external curl.exe through Shell I finished all steps for upload and publish. Maybe next step will be to change it to use MBS class.