use of twitter4j.TwitterException in project twitter4j by yusuke.
the class TwippleImageUpload method main.
/**
* Usage: java twitter4j.examples.media.TwippleImageUpload [image file path] [message]
*
* @param args message
*/
public static void main(String[] args) {
if (args.length < 1) {
System.out.println("Usage: java twitter4j.examples.media.TwippleImageUpload [image file path] [message]");
System.exit(-1);
}
try {
ImageUpload upload = new ImageUploadFactory().getInstance(MediaProvider.TWIPPLE);
String url;
if (args.length >= 2) {
url = upload.upload(new File(args[0]), args[1]);
} else {
url = upload.upload(new File(args[0]));
}
System.out.println("Successfully uploaded image to Twipple at " + url);
System.exit(0);
} catch (TwitterException te) {
te.printStackTrace();
System.out.println("Failed to upload the image: " + te.getMessage());
System.exit(-1);
}
}
use of twitter4j.TwitterException in project intellij-community by JetBrains.
the class StudyTwitterUtils method createTwitterDialogAndShow.
public static void createTwitterDialogAndShow(@NotNull Project project, @NotNull final StudyTwitterPluginConfigurator configurator, @NotNull Task task) {
ApplicationManager.getApplication().invokeLater(() -> {
DialogWrapper.DoNotAskOption doNotAskOption = createDoNotAskOption(project, configurator);
StudyTwitterUtils.TwitterDialogPanel panel = configurator.getTweetDialogPanel(task);
if (panel != null) {
TwitterDialogWrapper wrapper = new TwitterDialogWrapper(project, panel, doNotAskOption);
wrapper.setDoNotAskOption(doNotAskOption);
panel.addTextFieldVerifier(createTextFieldLengthDocumentListener(wrapper, panel));
if (wrapper.showAndGet()) {
try {
boolean isAuthorized = !configurator.getTwitterAccessToken(project).isEmpty();
Twitter twitter = getTwitter(configurator.getConsumerKey(project), configurator.getConsumerSecret(project));
if (!isAuthorized) {
authorizeAndUpdateStatus(project, twitter, panel);
} else {
setAuthInfoInTwitter(twitter, configurator.getTwitterAccessToken(project), configurator.getTwitterTokenSecret(project));
updateStatus(panel, twitter);
}
} catch (TwitterException | IOException e) {
LOG.warn(e.getMessage());
Messages.showErrorDialog("Status wasn\'t updated. Please, check internet connection and try again", "Twitter");
}
} else {
LOG.warn("Panel is null");
}
}
});
}
use of twitter4j.TwitterException in project ddf by codice.
the class TwitterSource method query.
@Override
public SourceResponse query(QueryRequest request) throws UnsupportedQueryException {
Twitter instance = twitterFactory.getInstance();
try {
instance.getOAuth2Token();
} catch (TwitterException e) {
throw new UnsupportedQueryException("Unable to get OAuth2 token.", e);
}
TwitterFilterVisitor visitor = new TwitterFilterVisitor();
request.getQuery().accept(visitor, null);
Query query = new Query();
query.setCount(request.getQuery().getPageSize());
if (visitor.hasSpatial()) {
GeoLocation geoLocation = new GeoLocation(visitor.getLatitude(), visitor.getLongitude());
query.setGeoCode(geoLocation, visitor.getRadius(), Query.Unit.km);
}
if (visitor.getContextualSearch() != null) {
query.setQuery(visitor.getContextualSearch().getSearchPhrase());
}
if (visitor.getTemporalSearch() != null) {
Calendar.Builder builder = new Calendar.Builder();
builder.setInstant(visitor.getTemporalSearch().getStartDate());
Calendar calendar = builder.build();
query.setSince(calendar.get(Calendar.YEAR) + "-" + calendar.get(Calendar.MONTH) + "-" + calendar.get(Calendar.DAY_OF_MONTH));
builder = new Calendar.Builder();
builder.setInstant(visitor.getTemporalSearch().getEndDate());
calendar = builder.build();
query.setUntil(calendar.get(Calendar.YEAR) + "-" + calendar.get(Calendar.MONTH) + "-" + calendar.get(Calendar.DAY_OF_MONTH));
}
QueryResult queryResult;
try {
queryResult = instance.search().search(query);
} catch (TwitterException e) {
throw new UnsupportedQueryException(e);
}
List<Result> resultList = new ArrayList<>(queryResult.getCount());
resultList.addAll(queryResult.getTweets().stream().map(status -> new ResultImpl(getMetacard(status))).collect(Collectors.toList()));
return new SourceResponseImpl(request, resultList);
}
Aggregations