简体   繁体   English

Twitter错误215使用Fabric Android SDK和Retrofit上传媒体

[英]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."}]} 我正在使用Rest API通过Retrofit将视频上传到Twitter,但有时,我在改装日志上收到内部服务器错误(500):{“errors”:[{“code”:215,“message”:“Bad Authentication数据。”}]}

The authentication process is done using Fabric: 身份验证过程使用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. 它有效,但是,我收到上述错误并不困难,通常是在de APPEND部分过程中。 I try to upload short videos and also those with the maximum duration allowed (about 30s), but it's the same scenario. 我尝试上传短视频以及允许的最长持续时间(约30秒),但这是相同的情况。

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. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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