media upload bugfix, version upgrade
This commit is contained in:
parent
e1aaa2fbf7
commit
d9ac1d8883
|
@ -12,8 +12,8 @@ android {
|
|||
applicationId 'org.nuclearfog.twidda'
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 33
|
||||
versionCode 61
|
||||
versionName '2.1'
|
||||
versionCode 62
|
||||
versionName '2.1.1'
|
||||
resConfigs 'en', 'de-rDE', 'zh-rCN'
|
||||
}
|
||||
|
||||
|
|
|
@ -1287,11 +1287,41 @@ public class Twitter implements GlobalSettings.SettingsListener {
|
|||
response = post(MEDIA_UPLOAD, params);
|
||||
if (response.code() < 200 || response.code() >= 300)
|
||||
throw new TwitterException(response);
|
||||
// skip step 4 if chunking isn#t enabled
|
||||
if (!enableChunk)
|
||||
return mediaId;
|
||||
|
||||
// step 4 STATUS
|
||||
params.clear();
|
||||
params.add("command=STATUS");
|
||||
params.add("media_id=" + mediaId);
|
||||
|
||||
int retries = 0;
|
||||
String state;
|
||||
do {
|
||||
response = get(MEDIA_UPLOAD, params);
|
||||
body = response.body();
|
||||
if (response.code() < 200 || response.code() >= 300 || body == null)
|
||||
throw new TwitterException(response);
|
||||
jsonResponse = new JSONObject(body.string());
|
||||
JSONObject processingInfo = jsonResponse.getJSONObject("processing_info");
|
||||
long retryAfter = processingInfo.optLong("check_after_secs");
|
||||
state = processingInfo.optString("state");
|
||||
// wait until next polling
|
||||
Thread.sleep(retryAfter * 1000L);
|
||||
} while (state.equals("in_progress") && ++retries <= 10);
|
||||
|
||||
// check if media processing was successfully
|
||||
if (!state.equals("succeeded")) {
|
||||
JSONObject jsonError = jsonResponse.getJSONObject("processing_info").getJSONObject("error");
|
||||
String message = jsonError.getString("message");
|
||||
throw new TwitterException(message);
|
||||
}
|
||||
return mediaId;
|
||||
} catch (IOException err) {
|
||||
err.printStackTrace();
|
||||
throw new TwitterException(err);
|
||||
} catch (JSONException err) {
|
||||
} catch (JSONException | InterruptedException err) {
|
||||
throw new TwitterException(err);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,13 @@ public class TwitterException extends Exception implements TwitterError {
|
|||
private int errorCode = -1;
|
||||
private int retryAfter = -1;
|
||||
|
||||
/**
|
||||
* @param message exception message
|
||||
*/
|
||||
TwitterException(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* create exception caused by another exception
|
||||
*/
|
||||
|
|
|
@ -46,15 +46,12 @@ public class TweetUpdater extends AsyncTask<TweetUpdate, Void, Void> {
|
|||
// upload media file and save media ID
|
||||
mediaIds[pos] = twitter.uploadMedia(mediaUpdates[pos]);
|
||||
}
|
||||
// fixme error when upoading video
|
||||
// upload tweet
|
||||
if (!isCancelled()) {
|
||||
twitter.uploadTweet(update, mediaIds);
|
||||
}
|
||||
} catch (TwitterException twException) {
|
||||
this.twException = twException;
|
||||
} catch (InterruptedException e) {
|
||||
// ignore
|
||||
} finally {
|
||||
// close inputstreams
|
||||
update.close();
|
||||
|
|
Loading…
Reference in New Issue