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());
}
}
});
}
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);
}
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();
}
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);
}
}
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;
}
}
Aggregations