Twitter error 215 using Fabric Android SDK and retrofitting to download media
I upload videos to Twitter using Rest API via Retrofit, but sometimes I get an internal server error (500) in the update 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 selecting a video and trying to send a message, I perform the following check:
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 for this it is necessary to carry out retrofitting:
@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);
Part of the tweet is 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 is not difficult, I get the above error, usually during the APPEND procedure. I am trying to download short videos as well as those that have the maximum length allowed (about 30 seconds), but this is the same scenario.
I would like to know if some parameter needs to be added for each request, like the user token, or if the user credentials are expiring faster than expected. Until now, I have not found out what is missing or not.
Thanks in advance.
source to share