Search in sources :

Example 86 with TwitterException

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);
    }
}
Also used : ImageUploadFactory(twitter4j.media.ImageUploadFactory) ImageUpload(twitter4j.media.ImageUpload) File(java.io.File) TwitterException(twitter4j.TwitterException)

Example 87 with TwitterException

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");
            }
        }
    });
}
Also used : Twitter(twitter4j.Twitter) IOException(java.io.IOException) TwitterException(twitter4j.TwitterException) DialogWrapper(com.intellij.openapi.ui.DialogWrapper)

Example 88 with TwitterException

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);
}
Also used : Query(twitter4j.Query) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ConfigurationBuilder(twitter4j.conf.ConfigurationBuilder) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Twitter(twitter4j.Twitter) ResultImpl(ddf.catalog.data.impl.ResultImpl) QueryResult(twitter4j.QueryResult) Result(ddf.catalog.data.Result) QueryResult(twitter4j.QueryResult) GeoLocation(twitter4j.GeoLocation) TwitterException(twitter4j.TwitterException)

Aggregations

TwitterException (twitter4j.TwitterException)88 Twitter (twitter4j.Twitter)69 TwitterFactory (twitter4j.TwitterFactory)54 Status (twitter4j.Status)19 Intent (android.content.Intent)9 User (twitter4j.User)8 ArrayList (java.util.ArrayList)7 File (java.io.File)6 DirectMessage (twitter4j.DirectMessage)6 IDs (twitter4j.IDs)6 Paging (twitter4j.Paging)6 Context (android.content.Context)4 AppSettings (com.klinker.android.twitter.settings.AppSettings)4 Date (java.util.Date)4 SavedSearch (twitter4j.SavedSearch)4 AccessToken (twitter4j.auth.AccessToken)4 MentionsDataSource (com.klinker.android.twitter.data.sq_lite.MentionsDataSource)3 IOException (java.io.IOException)3 UserList (twitter4j.UserList)3 RequestToken (twitter4j.auth.RequestToken)3