简体   繁体   中英

Twitter error 215 using Fabric Android SDK and Retrofit to upload media

I'm uploading videos to Twitter using the Rest API through Retrofit but, sometimes, I get the Internal Server Error (500) on retrofit logs: {"errors":[{"code":215,"message":"Bad Authentication data."}]}

The authentication process is done using Fabric:

 TwitterAuthConfig authConfig = new TwitterAuthConfig(CONSUMER_KEY, CONSUMER_SECRET);
 Fabric.with(this, new TwitterCore(authConfig), new TweetUi());
 twitterLoginButton.setCallback(new Callback<TwitterSession>() {

        @Override
        public void success(final Result<TwitterSession> result) {
            // Calls method to let user chose a media to upload
        }

        @Override
        public void failure(final TwitterException exception) {
            // Do something on failure
        }
    });

After select the video and try to post, I do the following verification:

AccountService accountService = TwitterCore.getInstance().getApiClient().getAccountService();
accountService.verifyCredentials(false, false, new Callback<User>() {

            @Override
            public void success(final Result<User> result) {
               // Calls retrofit to init upload video process 
            }

            @Override
            public void failure(final TwitterException exception) {
                // Do something on failure
            }
        });

And the retrofit call follows this:

@FormUrlEncoded()
@POST("/1.1/media/upload.json")
void uploadVideoInit(@Field("command") String command,
                     @Field("total_bytes") String totalBytes,
                     @Field("media_type") String mediaType,
                     Callback<T> callback);

@Multipart
@POST("/1.1/media/upload.json")
void uploadVideoAppend(@Part("command") String command,
                       @Part("media_id") String mediaId,
                       @Part("media") TypedFile media, // The raw binary file content being uploaded. Cannot be used with media_data.
                       // Required after an INIT, an index number starting at zero indicating the order of the uploaded chunks.
                       // The chunk of the upload for a single media, from 0-999, inclusive.
                       // The first segment_index is 0, the second segment uploaded is 1, etc.
                       @Part("segment_index") int segmentIndex,
                       Callback<T> callback);

@POST("/1.1/media/upload.json")
@FormUrlEncoded()
void uploadVideoFinalize(@Field("command") String command,
                         @Field("media_id") String mediaId,
                         Callback<T> callback);

The tweet part is like this:

@FormUrlEncoded
@POST("/1.1/statuses/update.json")
void update(@Field("status") String status,
            @Field("media_ids") String mediaIds,
            Callback<T> callback);

It works, but, it's not difficult I receive the mentioned above error, usually during de APPEND part of the process. I try to upload short videos and also those with the maximum duration allowed (about 30s), but it's the same scenario.

I'd like to know if I need to add some parameter to each request, like the user's token or if the user credentials expire soon than expected. Up until now I haven't found out what's missing or wrong.

Thanks in advance.

We already solved this problem. The thing is we were sending the chunk files without expect any result from server and immediatly continuing the process. By doing that, we were able to finish the process without problems. Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM