Search in sources :

Example 1 with TwitterException

use of twitter4j.TwitterException in project intellij-community by JetBrains.

the class StudyTwitterUtils method authorizeAndUpdateStatus.

/**
   * Show twitter dialog, asking user to tweet about his achievements. Post tweet with provided by panel
   * media and text. 
   * As a result of succeeded tweet twitter website is opened in default browser.
   */
public static void authorizeAndUpdateStatus(@NotNull final Project project, @NotNull final Twitter twitter, @NotNull final StudyTwitterUtils.TwitterDialogPanel panel) throws TwitterException {
    RequestToken requestToken = twitter.getOAuthRequestToken();
    BrowserUtil.browse(requestToken.getAuthorizationURL());
    ApplicationManager.getApplication().invokeLater(() -> {
        String pin = createAndShowPinDialog();
        if (pin != null) {
            try {
                AccessToken token = twitter.getOAuthAccessToken(requestToken, pin);
                StudyTwitterPluginConfigurator configurator = StudyUtils.getTwitterConfigurator(project);
                if (configurator != null) {
                    configurator.storeTwitterTokens(project, token.getToken(), token.getTokenSecret());
                    updateStatus(panel, twitter);
                } else {
                    LOG.warn("No twitter configurator is provided for the plugin");
                }
            } catch (TwitterException e) {
                if (e.getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
                    LOG.warn("Unable to get the access token.");
                    LOG.warn(e.getMessage());
                }
            } catch (IOException e) {
                LOG.warn(e.getMessage());
            }
        }
    });
}
Also used : RequestToken(twitter4j.auth.RequestToken) AccessToken(twitter4j.auth.AccessToken) IOException(java.io.IOException) StudyTwitterPluginConfigurator(com.jetbrains.edu.learning.StudyTwitterPluginConfigurator) TwitterException(twitter4j.TwitterException)

Example 2 with TwitterException

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

use of twitter4j.TwitterException in project twitter4j by yusuke.

the class PrintRawSampleStream method main.

/**
     * Main entry of this application.
     *
     * @param args arguments doesn't take effect with this example
     * @throws TwitterException when Twitter service or network is unavailable
     */
public static void main(String[] args) throws TwitterException {
    TwitterStream twitterStream = new TwitterStreamFactory().getInstance();
    RawStreamListener listener = new RawStreamListener() {

        @Override
        public void onMessage(String rawJSON) {
            System.out.println(rawJSON);
        }

        @Override
        public void onException(Exception ex) {
            ex.printStackTrace();
        }
    };
    twitterStream.addListener(listener);
    twitterStream.sample();
}
Also used : TwitterStreamFactory(twitter4j.TwitterStreamFactory) TwitterStream(twitter4j.TwitterStream) RawStreamListener(twitter4j.RawStreamListener) TwitterException(twitter4j.TwitterException)

Example 4 with TwitterException

use of twitter4j.TwitterException in project twitter4j by yusuke.

the class SendDirectMessage method main.

/**
     * Usage: java twitter4j.examples.directMessage.DirectMessage [recipient screen name] [message]
     *
     * @param args String[]
     */
public static void main(String[] args) {
    if (args.length < 2) {
        System.out.println("Usage: java twitter4j.examples.directmessage.SendDirectMessage [recipient screen name] [message]");
        System.exit(-1);
    }
    Twitter twitter = new TwitterFactory().getInstance();
    try {
        DirectMessage message = twitter.sendDirectMessage(args[0], args[1]);
        System.out.println("Direct message successfully sent to " + message.getRecipientScreenName());
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to send a direct message: " + te.getMessage());
        System.exit(-1);
    }
}
Also used : DirectMessage(twitter4j.DirectMessage) Twitter(twitter4j.Twitter) TwitterFactory(twitter4j.TwitterFactory) TwitterException(twitter4j.TwitterException)

Example 5 with TwitterException

use of twitter4j.TwitterException in project quorrabot by GloriousEggroll.

the class TwitterAPI method getlast.

public static String getlast() {
    try {
        List<Status> statuses = twitter.getUserTimeline();
        Status status = statuses.get(0);
        return status.getText();
    } catch (TwitterException te) {
        te.printStackTrace();
        return null;
    }
}
Also used : Status(twitter4j.Status) TwitterException(twitter4j.TwitterException)

Aggregations

TwitterException (twitter4j.TwitterException)112 Twitter (twitter4j.Twitter)78 TwitterFactory (twitter4j.TwitterFactory)59 Status (twitter4j.Status)27 Intent (android.content.Intent)13 User (twitter4j.User)13 ArrayList (java.util.ArrayList)11 DirectMessage (twitter4j.DirectMessage)9 AccessToken (twitter4j.auth.AccessToken)7 File (java.io.File)6 IDs (twitter4j.IDs)6 Context (android.content.Context)5 IOException (java.io.IOException)5 ConfigurationBuilder (twitter4j.conf.ConfigurationBuilder)5 Paging (twitter4j.Paging)4 RequestToken (twitter4j.auth.RequestToken)4 Activity (android.app.Activity)3 SharedPreferences (android.content.SharedPreferences)3 ActivityOptionsCompat (android.support.v4.app.ActivityOptionsCompat)3 View (android.view.View)3