[英]Twitter error 215 using Fabric Android SDK and Retrofit to upload media
我正在使用Rest API通過Retrofit將視頻上傳到Twitter,但有時,我在改裝日志上收到內部服務器錯誤(500):{“errors”:[{“code”:215,“message”:“Bad Authentication數據。”}]}
身份驗證過程使用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
}
});
選擇視頻並嘗試發布后,我會進行以下驗證:
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
}
});
改裝電話如下:
@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);
推文部分是這樣的:
@FormUrlEncoded
@POST("/1.1/statuses/update.json")
void update(@Field("status") String status,
@Field("media_ids") String mediaIds,
Callback<T> callback);
它有效,但是,我收到上述錯誤並不困難,通常是在de APPEND部分過程中。 我嘗試上傳短視頻以及允許的最長持續時間(約30秒),但這是相同的情況。
我想知道是否需要為每個請求添加一些參數,例如用戶的令牌,或者用戶憑據是否會很快到期。 到目前為止,我還沒有發現什么是遺漏或錯誤的。
提前致謝。
我們已經解決了這個問題。 問題是我們正在發送塊文件而不期望服務器的任何結果並立即繼續該過程。 通過這樣做,我們能夠毫無問題地完成整個過程。 謝謝。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.