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

时间:2015-07-31 20:43:23

标签: android twitter retrofit twitter-fabric

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.

1 个答案:

答案 0 :(得分:2)

我们已经解决了这个问题。问题是我们正在发送块文件而不期望服务器的任何结果并立即继续该过程。通过这样做,我们能够毫无问题地完成整个过程。感谢。