Media/uploads (INIT)(APPNED)(FINALIZE) succuss but video not showing on twitter

android

#1

First i get media id using media/upload (INIT) and then used media/upload(APPEND)
and finally i used media/upload(FINALIZE) as twitter doc says:- i get successful response i all three section but still my video is not showing over twitter…my code is

public void tweet(TwitterSession pTwitterSession, final File file, final String selectedVideoPath) {
    showProgressDialogResult();
    final MyTwitterApiClient twitterApiClient = new MyTwitterApiClient(pTwitterSession);
    Log.d("video", "File Size is " + (file.length() / 1024 / 1024) + "mb");
    try {
        final byte data[] = Utils.readBytesFromFile(selectedVideoPath);
        Call<Media> initVideio = twitterApiClient.getCustomService().uploadVideoInit("Example", "INIT", String.valueOf(file.length()), "video/mp4");
        initVideio.enqueue(new Callback<Media>() { //XXX refactor this callback hell
            @Override
            public void success(final Result<Media> result) {
                Log.d("id", "media ID is " + result.data.mediaId);
                Log.d("id", "media ID String is " + result.data.mediaIdString);

                //  final long mediaId = result.data.mediaId;
                final int fileSize = (int) file.length();
                Log.d("Succeed FileSize ", "" + fileSize);

                uploadChunk(data, result.data.mediaId, fileSize, 0, selectedVideoPath);
            }

            @Override
            public void failure(final TwitterException exception) {
                hideProgressDialogResult();
                Log.d("failed", "Failed twitter init with " + exception);
            }
        });
    } catch (Exception pE) {
        hideProgressDialogResult();
        pE.printStackTrace();
    }
}

public void uploadChunk(final byte data[],
                         final long mediaId,
                         final int fileSize,
                         final int chunkPart,
                         final String selectedVideoPath) {
    final int maxChunk = 4 * 1000 * 1000;
    final int byteSent = chunkPart * maxChunk;
    final boolean isLast = byteSent + maxChunk >= fileSize;
    final RequestBody body = new RequestBody() {
        @Override
        public MediaType contentType() {
            return MediaType.parse("video/mp4");
        }

        @Override
        public void writeTo(final BufferedSink sink) throws IOException {
            sink.write(data, byteSent, isLast ? fileSize - byteSent : maxChunk);

        }
    };

    String fileBase64 = "";
    try {
        fileBase64 = Utils.encodeFileToBase64Binary(selectedVideoPath);
    } catch (IOException e) {
        e.printStackTrace();
    }
    TwitterSession session = Twitter.getSessionManager().getActiveSession();
    final MyTwitterApiClient twitterApiClient = new MyTwitterApiClient(session);

    final RequestBody message = RequestBody.create(MediaType.parse("multipart/form-data"), "Example");
    final RequestBody appendCommand = RequestBody.create(MediaType.parse("multipart/form-data"), "APPEND");
    final RequestBody vedioMediaId = RequestBody.create(MediaType.parse("multipart/form-data"), String.valueOf(mediaId));
    final RequestBody bytes = RequestBody.create(MediaType.parse("multipart/form-data"), String.valueOf(chunkPart));
    final RequestBody media_data = RequestBody.create(MediaType.parse("multipart/form-data"), fileBase64);

    Call<Media> appendVideio = twitterApiClient.getCustomService().uploadVideoAppend(message,
            appendCommand,
            vedioMediaId,
            bytes,
            body,
            media_data);

    appendVideio.enqueue(new Callback<Media>() {
        @Override
        public void success(Result result) {
            Log.e("AppnedSucussMessage", result.response.message());
            Log.d("TAG", "Uploaded video part");


            if (isLast) {
                TwitterSession session = Twitter.getSessionManager().getActiveSession();
                final MyTwitterApiClient twitterApiClient = new MyTwitterApiClient(session);
                final RequestBody description = RequestBody.create(MediaType.parse("multipart/form-data"), "Example");
                final RequestBody finalizeCommand = RequestBody.create(MediaType.parse("multipart/form-data"), "FINALIZE");
                final RequestBody id = RequestBody.create(MediaType.parse("multipart/form-data"), String.valueOf(mediaId));

                Call<Media> finalizeVideio = twitterApiClient.getCustomService().uploadVideoFinalize(
                        description,
                        finalizeCommand,
                        id);

                finalizeVideio.enqueue(new Callback<Media>() {
                    @Override
                    public void success(final Result<Media> result) {
                        Log.d("result", "" + result.data.mediaIdString);
                        Log.e("TAG", "Finalized upload !");
postVideoTweet("example",result.data.mediaId)
                    }

                    @Override
                    public void failure(final TwitterException exception) {
                        exception.printStackTrace();
                        hideProgressDialogResult();

                        Log.e("TAG", "Failed upload finalization");
                    }
                });
            } else {
                Log.e("Pending", "start chunked again");
                uploadChunk(data, mediaId, fileSize, chunkPart + 1, selectedVideoPath);
            }
        }

        @Override
        public void failure(final TwitterException exception) {
            exception.printStackTrace();
            hideProgressDialogResult();

            Log.e("TAG", "Could not upload video: " + exception);
        }
    });
}

private void postVideoTweet(String text, long mediaId) {
    StatusesService statusesService = TwitterCore.getInstance().getApiClient().getStatusesService();
    Call<Tweet> tweetCall = statusesService.update(text, null, false, null, null, null, false, false, String.valueOf(mediaId));
    tweetCall.enqueue(new Callback<Tweet>() {
        @Override
        public void success(Result<Tweet> result) {
            Log.d("result", result.data.idStr);


        }

        @Override
        public void failure(TwitterException exception) {
            hideProgressDialogResult();
            exception.printStackTrace();

        }



    });
}

I am using video size 1 mb only.
I got successful callback result with media id after i enqueue final media/uploads (FINALIZE). the id is=963736242184536064,and use this media id with Statuses/update it give me error…
com.twitter.sdk.android.core.TwitterApiException: HTTP request failed, Status: 400


Twitter video upload fail on Android
#2

Any feedback on this…i need this to implement as soon as possible…