The video uploaded is never posted on Twitter

video
twitter4j
media-upload
java

#1

I use chunked video upload to post videos on Twitter from my java web application. The requests(init, append and finalize) are sent successfully to the https://upload.twitter.com/1.1/media/upload.json, but the video is never posted on Twitter.
Can anyone help me please?


#3

Can you provide example code and the responses?

Are there any errors returned?

What are you doing to attach your media to an actual Tweet? are there any errors returned from that call?


#4

Thanks for your reply! There is no errors displayed in the console and the responses of the commands init, append and finalize contain the same fields (size, media_id_string, media_id…) listed in the documentation. I use the twitter4j library and because they did not (still now) add the implementation of the uploadMediaChunked() function in the .jar I add it by myself to my local jar and use the function. Is the problem comming from here (because in the last officiel version of the twitter4j.jar there is no uploadMediaChunked function)? Does Twitter verify if any function is in the twitter4j officiel library?


#5

No, it is a third party library that we don’t “verify” as such - although we know the creator very well :smile:

I’m afraid it is really difficult to debug without more information about any errors that might be returned, particularly from the statuses/update call. Are you checking the STATUS of the upload before adding the media to a Tweet?


#6

I have a question please about the statusUpdate: if I use this
UploadedMedia media = twitter.uploadMediaChunked(file);
how can I use it in the statusUpdate.setMedia() ? Must I write statusUpdate.setMedia(media.getMediaId() ) or statusUpdate.setMedia(media) ?


#7

I don’t think you should ask this type of question directly on twittercommunity.
If you need to write code with a specific library open a new issue on their github or ask on stackoverflow.

The moderators of TwitterCommunity are already very busy and they usually only work on the problems coming from their API.


#8

Otherwise concerning your problem, I have experienced the same thing too in the past and it is usually caused by the video being considered as invalid by Twitter even though it respects every criteria stated in the documentation.

What I would suggest is to take a sample video that you know work and try it out.
Also note that if a video works from the Android/iOS Twitter app it does not mean it will work with the upload endpoint because the video is compressed before being sent via the upload endpoint.


#9

I’m sorry if I post this kind of question here. But if I did it, it’s because I asked about this issue in github, stackoverflow many times but I didn’t get any solution. Thank you for your reply and excuse me another time.


#10

You don’t have to be sorry, I am just trying to explain the goal of the forum ;).
I personally gave up Twitter4J, 4 years ago, so I cannot help you more on this library.

I will suggest that you get a very clear explanation of what you are trying to do and then ask the question in a new post on stackoverflow.


#11

I don’t know for sure as I don’t use Twitter4J all the time, but I think you would want to use the first one - at least at the Twitter API level, the statuses/update endpoint needs the media ID not the media object.


#12

Thank you for your effort! I attach now the media_id to the text. When I test it, only the text is posted. In the console I see that the endpoint is statuses/update. Are you sure that the correct endpoint is the statuses/update and not statuses/update_with_media?


#13

Yes the correct endpoint is /update. Have you tried with other videos, as I told you I can experience the exact same problem when uploading video that is not “recognized” by Twitter.

The api does not throw an exception but the tweet will just not have any video attached.


#14

Yes I tried with other videos but it doesn’t work. I still have only the text posted. I will keep testing and tell you when it works. Thank you again for your help :slight_smile: !


#15

Unfortunately it doesn’t work. I don’t know what is wrong in what I’m doing. This is my code: `

Twitter twitter = new TwitterFactory().getInstance();
            twitter.setOAuthConsumer(consumerKey, consumerSecret);
            AccessToken accessToken = new AccessToken(accessTokenStr,accessTokenSecret);
            twitter.setOAuthAccessToken(accessToken);
            File file = new File("D:/doc/test2.mp4");
            UploadedMedia media = twitter.uploadMediaChunked(file);
            StatusUpdate statusUpdate = new StatusUpdate(text);
            statusUpdate.setMedia(media.getMediaId());
            twitter.updateStatus(statusUpdate.inReplyToStatusId(tweetId));`

and this is the statuses/update response in the console:

[DEBUG] twitter4j.HttpClientImpl - Request: 
[DEBUG] twitter4j.HttpClientImpl - POST https://api.twitter.com/1.1/statuses/update.json
[DEBUG] twitter4j.auth.OAuthAuthorization - OAuth base string: POST&https%3A%2F%2Fapi.twitter.com%2F1.1%2Fstatuses%2Fupdate.json&in_reply_to_status_id%xxxxxxxxxxxx%26include_entities%3Dtrue%26oauth_consumer_key%3xxxxxxxxx%26oauth_nonce%xxxxxxxx%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1462958258%26oauth_token%xxxxxxx-xxxxxxxxxxxxxx%26oauth_version%3D1.0%26status%3D%xxxxxxxxxxx%2520Testing...
[DEBUG] twitter4j.auth.OAuthAuthorization - OAuth signature: xxxxxxxxxxxxxx
[DEBUG] twitter4j.HttpClientImpl - Authorization: **********************************************************************************************************************************************************************************************************************************************************************************
[DEBUG] twitter4j.HttpClientImpl - X-Twitter-Client-Version: 4.0.5-SNAPSHOT
[DEBUG] twitter4j.HttpClientImpl - X-Twitter-Client-URL: http://twitter4j.org/en/twitter4j-4.0.5-SNAPSHOT.xml
[DEBUG] twitter4j.HttpClientImpl - X-Twitter-Client: Twitter4J
[DEBUG] twitter4j.HttpClientImpl - User-Agent: twitter4j http://twitter4j.org/ /4.0.5-SNAPSHOT
[DEBUG] twitter4j.HttpClientImpl - Accept-Encoding: gzip
[DEBUG] twitter4j.HttpClientImpl - Post Params: status=%xxxxxxxxxxxxxx%20Testing...&in_reply_to_status_id=xxxxxxxxxxxxxxx&include_entities=true
[DEBUG] sun.net.www.protocol.http.HttpURLConnection - sun.net.www.MessageHeader@3915840e12 pairs: {POST /1.1/statuses/update.json HTTP/1.1: null}{Authorization: OAuth oauth_consumer_key="xxxxxxxxxxxx",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1462958258",oauth_nonce="xxxxxxxxx",oauth_version="1.0",oauth_token="xxxxxxxxxxxxx-xxxxxxxxxxxx",oauth_signature="Cz%xxxxxxxxxx%3D"}{X-Twitter-Client-Version: 4.0.5-SNAPSHOT}{X-Twitter-Client-URL: http://twitter4j.org/en/twitter4j-4.0.5-SNAPSHOT.xml}{X-Twitter-Client: Twitter4J}{User-Agent: twitter4j http://twitter4j.org/ /4.0.5-SNAPSHOT}{Accept-Encoding: gzip}{Content-Type: application/x-www-form-urlencoded}{Host: api.twitter.com}{Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2}{Connection: keep-alive}{Content-Length: 95}
[DEBUG] sun.net.www.protocol.http.HttpURLConnection - sun.net.www.MessageHeader@11f6d60f24 pairs: {null: HTTP/1.1 200 OK}{cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0}{content-disposition: attachment; filename=json.json}{content-encoding: gzip}{content-length: 811}{content-type: application/json;charset=utf-8}{date: Wed, 11 May 2016 09:16:46 GMT}{expires: Tue, 31 Mar 1981 05:00:00 GMT}{last-modified: Wed, 11 May 2016 09:16:46 GMT}{pragma: no-cache}{server: tsa_b}{set-cookie: lang=fr; Path=/}{set-cookie: guest_id=v1%3A146295820612007568; Domain=.twitter.com; Path=/; Expires=Fri, 11-May-2018 09:16:46 UTC}{status: 200 OK}{strict-transport-security: max-age=631138519}{x-access-level: read-write-directmessages}{x-connection-hash: 7804c6d5faa9abb18ab9e2868b58659e}{x-content-type-options: nosniff}{x-frame-options: SAMEORIGIN}{x-response-time: 92}{x-transaction: 820ff9ff1a123571}{x-tsa-request-body-time: 0}{x-twitter-response-tags: BouncerCompliant}{x-xss-protection: 1; mode=block}
[DEBUG] twitter4j.HttpClientImpl - Response: 
[DEBUG] twitter4j.HttpClientImpl - date: Wed, 11 May 2016 09:16:46 GMT
[DEBUG] twitter4j.HttpClientImpl - HTTP/1.1 200 OK
[DEBUG] twitter4j.HttpClientImpl - server: tsa_b
[DEBUG] twitter4j.HttpClientImpl - content-length: 811
[DEBUG] twitter4j.HttpClientImpl - x-tsa-request-body-time: 0
[DEBUG] twitter4j.HttpClientImpl - expires: Tue, 31 Mar 1981 05:00:00 GMT
[DEBUG] twitter4j.HttpClientImpl - x-response-time: 92
[DEBUG] twitter4j.HttpClientImpl - x-frame-options: SAMEORIGIN
[DEBUG] twitter4j.HttpClientImpl - content-encoding: gzip
[DEBUG] twitter4j.HttpClientImpl - x-transaction: 820ff9ff1a123571
[DEBUG] twitter4j.HttpClientImpl - strict-transport-security: max-age=631138519
[DEBUG] twitter4j.HttpClientImpl - pragma: no-cache
[DEBUG] twitter4j.HttpClientImpl - set-cookie: guest_id=v1%3A146295820612007568; Domain=.twitter.com; Path=/; Expires=Fri, 11-May-2018 09:16:46 UTC
[DEBUG] twitter4j.HttpClientImpl - set-cookie: lang=fr; Path=/
[DEBUG] twitter4j.HttpClientImpl - last-modified: Wed, 11 May 2016 09:16:46 GMT
[DEBUG] twitter4j.HttpClientImpl - x-xss-protection: 1; mode=block
[DEBUG] twitter4j.HttpClientImpl - x-content-type-options: nosniff
[DEBUG] twitter4j.HttpClientImpl - content-disposition: attachment; filename=json.json
[DEBUG] twitter4j.HttpClientImpl - x-connection-hash: 7804c6d5faa9abb18ab9e2868b58659e
[DEBUG] twitter4j.HttpClientImpl - x-access-level: read-write-directmessages
[DEBUG] twitter4j.HttpClientImpl - x-twitter-response-tags: BouncerCompliant
[DEBUG] twitter4j.HttpClientImpl - content-type: application/json;charset=utf-8
[DEBUG] twitter4j.HttpClientImpl - cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
[DEBUG] twitter4j.HttpClientImpl - status: 200 OK

Is the problem from here {Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2}?


#16

Could you put the video you are trying to upload on a public host so that I can try with it?


#17

I test with many videos between them this one http://www.w3schools.com/html/mov_bbb.mp4


#18

I have just checked and the video is compatible.

If you are not tied to java, you could use the C# library I am working on (Tweetinvi).
You would only have to use the following code :

var binary = File.ReadAllBytes(@"C:\videos\mov_bbb.mp4");
var media = Upload.UploadVideo(binary);

var tweet = Tweet.PublishTweet("hello", new PublishTweetOptionalParameters
{
    Medias = {media}
});

If you can’t use C# then I would suggest implementing the Http multi-part request on your own, or debug the Twitter4J source code.

Or you can also look at the query executed by Tweetinvi and then compare it with the one performed by Twitter4J.


#19

hello sir,

I use twitter4j too but I cannot find twitter.uploadMediaChunked();
can you please help me?

thank you


#20

I believe this was patched in to the library via one of the pull requests on Github - there are two open PRs to add this function, but it is not yet in the released version of twitter4j.