Search in sources :

Example 1 with JSONException

use of twitter4j.JSONException in project twitter4j by yusuke.

the class MobypictureUpload method postUpload.

@Override
protected String postUpload() throws TwitterException {
    int statusCode = httpResponse.getStatusCode();
    if (statusCode != 200)
        throw new TwitterException("Mobypic image upload returned invalid status code", httpResponse);
    String response = httpResponse.asString();
    try {
        JSONObject json = new JSONObject(response);
        if (!json.isNull("media")) {
            return json.getJSONObject("media").getString("mediaurl");
        }
    } catch (JSONException e) {
        throw new TwitterException("Invalid Mobypic response: " + response, e);
    }
    throw new TwitterException("Unknown Mobypic response", httpResponse);
}
Also used : JSONObject(twitter4j.JSONObject) JSONException(twitter4j.JSONException) TwitterException(twitter4j.TwitterException)

Example 2 with JSONException

use of twitter4j.JSONException in project twitter4j by yusuke.

the class ImgLyUpload method postUpload.

@Override
protected String postUpload() throws TwitterException {
    int statusCode = httpResponse.getStatusCode();
    if (statusCode != 200)
        throw new TwitterException("ImgLy image upload returned invalid status code", httpResponse);
    String response = httpResponse.asString();
    try {
        JSONObject json = new JSONObject(response);
        if (!json.isNull("url"))
            return json.getString("url");
    } catch (JSONException e) {
        throw new TwitterException("Invalid ImgLy response: " + response, e);
    }
    throw new TwitterException("Unknown ImgLy response", httpResponse);
}
Also used : JSONObject(twitter4j.JSONObject) JSONException(twitter4j.JSONException) TwitterException(twitter4j.TwitterException)

Aggregations

JSONException (twitter4j.JSONException)2 JSONObject (twitter4j.JSONObject)2 TwitterException (twitter4j.TwitterException)2