Search in sources :

Example 61 with TwitterException

use of twitter4j.TwitterException in project android-priority-jobqueue by yigit.

the class PostTweetJob method shouldReRunOnThrowable.

@Override
protected RetryConstraint shouldReRunOnThrowable(Throwable throwable, int runCount, int maxRunCount) {
    if (throwable instanceof TwitterException) {
        //if it is a 4xx error, stop
        TwitterException twitterException = (TwitterException) throwable;
        int errorCode = twitterException.getErrorCode();
        return errorCode < 400 || errorCode > 499 ? RetryConstraint.RETRY : RetryConstraint.CANCEL;
    }
    return RetryConstraint.RETRY;
}
Also used : TwitterException(twitter4j.TwitterException) RetryConstraint(com.birbit.android.jobqueue.RetryConstraint)

Example 62 with TwitterException

use of twitter4j.TwitterException in project twitter4j by yusuke.

the class ShowStatus method main.

/**
     * Usage: java twitter4j.examples.tweets.ShowStatus [status id]
     *
     * @param args message
     */
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("Usage: java twitter4j.examples.tweets.ShowStatus [status id]");
        System.exit(-1);
    }
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        Status status = twitter.showStatus(Long.parseLong(args[0]));
        System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to show status: " + te.getMessage());
        System.exit(-1);
    }
}
Also used : Status(twitter4j.Status) Twitter(twitter4j.Twitter) TwitterFactory(twitter4j.TwitterFactory) TwitterException(twitter4j.TwitterException)

Example 63 with TwitterException

use of twitter4j.TwitterException in project twitter4j by yusuke.

the class UploadMultipleImages method main.

/**
     * Usage: java twitter4j.examples.tweets.UploadMultipleImages [text] [file1] [file2] ...
     *
     * @param args message
     */
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("Usage: java twitter4j.examples.tweets.UploadMultipleImages [text] [file1] [file2] ...");
        System.exit(-1);
    }
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        long[] mediaIds = new long[args.length - 1];
        for (int i = 1; i < args.length; i++) {
            System.out.println("Uploading...[" + i + "/" + (args.length - 1) + "][" + args[i] + "]");
            UploadedMedia media = twitter.uploadMedia(new File(args[i]));
            System.out.println("Uploaded: id=" + media.getMediaId() + ", w=" + media.getImageWidth() + ", h=" + media.getImageHeight() + ", type=" + media.getImageType() + ", size=" + media.getSize());
            mediaIds[i - 1] = media.getMediaId();
        }
        StatusUpdate update = new StatusUpdate(args[0]);
        update.setMediaIds(mediaIds);
        Status status = twitter.updateStatus(update);
        System.out.println("Successfully updated the status to [" + status.getText() + "][" + status.getId() + "].");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to update status: " + te.getMessage());
        System.exit(-1);
    }
}
Also used : StatusUpdate(twitter4j.StatusUpdate) Status(twitter4j.Status) UploadedMedia(twitter4j.UploadedMedia) Twitter(twitter4j.Twitter) TwitterFactory(twitter4j.TwitterFactory) File(java.io.File) TwitterException(twitter4j.TwitterException)

Example 64 with TwitterException

use of twitter4j.TwitterException 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)

Example 65 with TwitterException

use of twitter4j.TwitterException in project twitter4j by yusuke.

the class CreateFavorite method main.

/**
     * Usage: java twitter4j.examples.favorite.CreateFavorite [status id]
     *
     * @param args message
     */
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("Usage: java twitter4j.examples.favorite.CreateFavorite [status id]");
        System.exit(-1);
    }
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        twitter.createFavorite(Long.parseLong(args[0]));
        System.out.println("Successfully favorited status [" + args[0] + "].");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to favorite status: " + te.getMessage());
        System.exit(-1);
    }
}
Also used : Twitter(twitter4j.Twitter) TwitterFactory(twitter4j.TwitterFactory) TwitterException(twitter4j.TwitterException)

Aggregations

TwitterException (twitter4j.TwitterException)96 Twitter (twitter4j.Twitter)69 TwitterFactory (twitter4j.TwitterFactory)54 Status (twitter4j.Status)21 User (twitter4j.User)12 Intent (android.content.Intent)11 ArrayList (java.util.ArrayList)9 File (java.io.File)6 IDs (twitter4j.IDs)6 Context (android.content.Context)5 Date (java.util.Date)4 DirectMessage (twitter4j.DirectMessage)4 Paging (twitter4j.Paging)4 AccessToken (twitter4j.auth.AccessToken)4 Activity (android.app.Activity)3 SharedPreferences (android.content.SharedPreferences)3 ActivityOptionsCompat (android.support.v4.app.ActivityOptionsCompat)3 View (android.view.View)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3