1

I am currently trying to build an application to post videos to Twitter on behalf of a user.

So I currently have the application-key, application-secret, access-token and access-secret.

final TwitterTemplate twitterTemplate = new TwitterTemplate(
    "application-key",
    "application-secret",
    "access-token",
    "access-secret");

So using this I can actually post a tweet containing only text. If I want to include an image I have to include the workaround "solution" posted on a bug of spring-social-twitter. This resolves the image but the video still cannot be uploaded.

So the rational thinking was to try out this upload with postman to "isolate" the call itself.

Auth1 of postman

In the previous image we can see the Authorization process. This is the same for Every single call I make.

with this Auth a simple POST to https://api.twitter.com/1.1/statuses/update.json?status=hello works. Same with 2 calls for image.

  1. POST to https://upload.twitter.com/1.1/media/upload.json?media_category=tweet_image for the image upload ( body -> media : image ).
  2. POST to https://api.twitter.com/1.1/statuses/update.json merge the media_id with a new tweet.

But back to the video following again the official guide of twitter when I send this video init req

the response is

could not auth resp

when the request media_type does not contain / then a valid response will return from tweeter with a media_id, lets call it X. So I append a video ( second command ) on X and then finalize the video ( third command ) on X. But as expected the response is

unrecognized media resp

as the media_type was never provided. On the other hand if the video on the second step is pushed as base64 encoded ( and including the header for base64 encoding) then a response of

invalid size resp

No matter what I have done so far I cannot make it post a video. I even used Postman as a proxy for twurl and captured the request of twurl that did upload the video. Changed the auth with mine ( because of nonce it requires to be recreated ) and the request failed to upload the video!

some notes :

  1. the credentials are up to dates and work from twurl.
  2. the video is valid and can be uploaded from both tweeter ui and twurl upload command.
  3. the base64 convert was encoded / decoded with linux base64 tool piped to file and validated that the size is the same.

If any other clarification is required please let me know!

Thank you in advance

Michael Michailidis
  • 1,002
  • 1
  • 8
  • 21

1 Answers1

0

I know it's late but in case someone has same question, to upload video on twitter you have to use chunked-media-upload method.

here's the reference https://developer.twitter.com/en/docs/media/upload-media/uploading-media/chunked-media-upload

Rudra
  • 704
  • 8
  • 16