Search in sources :

Example 56 with Twitter

use of twitter4j.Twitter in project twicalico by moko256.

the class GlobalApplication method getTwitterInstance.

@NonNull
public Twitter getTwitterInstance(@NonNull AccessToken accessToken) {
    Twitter t;
    Configuration conf;
    if (accessToken.getType() == Type.TWITTER) {
        conf = new ConfigurationBuilder().setTweetModeExtended(true).setOAuthConsumerKey(BuildConfig.CONSUMER_KEY).setOAuthConsumerSecret(BuildConfig.CONSUMER_SECRET).setOAuthAccessToken(accessToken.getToken()).setOAuthAccessTokenSecret(accessToken.getTokenSecret()).build();
        t = twitterCache.get(conf);
        if (t == null) {
            t = new TwitterFactory(conf).getInstance();
            twitterCache.put(conf, t);
        }
    } else {
        conf = new ConfigurationBuilder().setOAuthAccessToken(accessToken.getToken()).setRestBaseURL(accessToken.getUrl()).build();
        t = twitterCache.get(conf);
        if (t == null) {
            t = new MastodonTwitterImpl(conf, accessToken.getUserId(), getOkHttpClient(conf.getHttpClientConfiguration()).newBuilder());
            twitterCache.put(conf, t);
        }
    }
    return t;
}
Also used : ConfigurationBuilder(twitter4j.conf.ConfigurationBuilder) AppConfiguration(com.github.moko256.twicalico.config.AppConfiguration) HttpClientConfiguration(twitter4j.HttpClientConfiguration) Configuration(twitter4j.conf.Configuration) Twitter(twitter4j.Twitter) TwitterFactory(twitter4j.TwitterFactory) MastodonTwitterImpl(com.github.moko256.mastodon.MastodonTwitterImpl) NonNull(android.support.annotation.NonNull)

Example 57 with Twitter

use of twitter4j.Twitter in project opennms by OpenNMS.

the class MicroblogNotificationStrategy method send.

/**
 * {@inheritDoc}
 */
@Override
public int send(List<Argument> arguments) {
    Twitter svc = buildUblogService(arguments);
    String messageBody = buildMessageBody(arguments);
    Status response;
    final String baseURL = svc.getConfiguration().getClientURL();
    LOG.debug("Dispatching microblog notification at base URL '{}' with message '{}'", baseURL, messageBody);
    try {
        response = svc.updateStatus(messageBody);
    } catch (TwitterException e) {
        LOG.error("Microblog notification failed at service URL '{}'", baseURL, e);
        return 1;
    }
    LOG.info("Microblog notification succeeded: update posted with ID {}", response.getId());
    return 0;
}
Also used : Status(twitter4j.Status) Twitter(twitter4j.Twitter) TwitterException(twitter4j.TwitterException)

Example 58 with Twitter

use of twitter4j.Twitter in project opennms by OpenNMS.

the class MicroblogReplyNotificationStrategy method send.

/**
 * {@inheritDoc}
 */
@Override
public int send(final List<Argument> arguments) {
    final Twitter svc = buildUblogService(arguments);
    String destUser = findDestName(arguments);
    Status response;
    if (destUser == null || "".equals(destUser)) {
        LOG.error("Cannot send a microblog reply notice to a user with no microblog username set. Either set a microblog username for this OpenNMS user or use the MicroblogUpdateNotificationStrategy instead.");
        return 1;
    }
    // In case the user tried to be helpful, avoid a double @@
    if (destUser.startsWith("@"))
        destUser = destUser.substring(1);
    final String fullMessage = String.format("@%s %s", destUser, buildMessageBody(arguments));
    LOG.debug("Dispatching microblog reply notification at base URL '{}' with message '{}'", svc.getConfiguration().getClientURL(), fullMessage);
    try {
        response = svc.updateStatus(fullMessage);
    } catch (final TwitterException e) {
        LOG.error("Microblog notification failed at service URL '{}'", svc.getConfiguration().getClientURL(), e);
        return 1;
    }
    LOG.info("Microblog reply notification succeeded: reply update posted with ID {}", response.getId());
    return 0;
}
Also used : Status(twitter4j.Status) Twitter(twitter4j.Twitter) TwitterException(twitter4j.TwitterException)

Example 59 with Twitter

use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.

the class FavoritesActivity method getFavorites.

public void getFavorites() {
    if (!hasMore) {
        return;
    }
    canRefresh = false;
    final LinearLayout spinner = (LinearLayout) findViewById(R.id.list_progress);
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);
                final ResponseList<twitter4j.Status> favs = twitter.getFavorites(paging);
                if (favs.size() < 17) {
                    hasMore = false;
                }
                paging.setPage(paging.getPage() + 1);
                for (twitter4j.Status s : favs) {
                    statuses.add(s);
                }
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        if (adapter == null) {
                            if (statuses.size() > 0) {
                                adapter = new TimelineArrayAdapter(context, statuses, TimelineArrayAdapter.FAVORITE);
                                listView.setAdapter(adapter);
                                listView.setVisibility(View.VISIBLE);
                            } else {
                                LinearLayout nothing = (LinearLayout) findViewById(R.id.no_content);
                                nothing.setVisibility(View.VISIBLE);
                                listView.setVisibility(View.GONE);
                                hasMore = false;
                            }
                        } else {
                            adapter.notifyDataSetChanged();
                        }
                        spinner.setVisibility(View.GONE);
                        canRefresh = true;
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        spinner.setVisibility(View.GONE);
                        canRefresh = false;
                    }
                });
            } catch (OutOfMemoryError e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        spinner.setVisibility(View.GONE);
                        canRefresh = false;
                    }
                });
            }
        }
    }).start();
}
Also used : Status(twitter4j.Status) Twitter(twitter4j.Twitter) LoginActivity(com.klinker.android.twitter.activities.setup.LoginActivity) MainActivity(com.klinker.android.twitter.activities.MainActivity) Activity(android.app.Activity) Status(twitter4j.Status) TimelineArrayAdapter(com.klinker.android.twitter.adapters.TimelineArrayAdapter) LinearLayout(android.widget.LinearLayout)

Example 60 with Twitter

use of twitter4j.Twitter in project Talon-for-Twitter by klinker24.

the class RetweetActivity method getRetweets.

public void getRetweets() {
    if (!hasMore) {
        return;
    }
    canRefresh = false;
    final LinearLayout spinner = (LinearLayout) findViewById(R.id.list_progress);
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Twitter twitter = Utils.getTwitter(context, settings);
                final ResponseList<twitter4j.Status> favs = twitter.getRetweetsOfMe(paging);
                if (favs.size() < 17) {
                    hasMore = false;
                }
                paging.setPage(paging.getPage() + 1);
                for (twitter4j.Status s : favs) {
                    statuses.add(s);
                }
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        if (adapter == null) {
                            if (statuses.size() > 0) {
                                adapter = new TimelineArrayAdapter(context, statuses, TimelineArrayAdapter.RETWEET);
                                listView.setAdapter(adapter);
                                listView.setVisibility(View.VISIBLE);
                            } else {
                                LinearLayout nothing = (LinearLayout) findViewById(R.id.no_content);
                                try {
                                    nothing.setVisibility(View.VISIBLE);
                                } catch (Exception e) {
                                }
                                listView.setVisibility(View.GONE);
                            }
                        } else {
                            adapter.notifyDataSetChanged();
                        }
                        spinner.setVisibility(View.GONE);
                        canRefresh = true;
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        spinner.setVisibility(View.GONE);
                        canRefresh = false;
                    }
                });
            } catch (OutOfMemoryError e) {
                e.printStackTrace();
                ((Activity) context).runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        spinner.setVisibility(View.GONE);
                        canRefresh = false;
                    }
                });
            }
        }
    }).start();
}
Also used : Status(twitter4j.Status) Twitter(twitter4j.Twitter) LoginActivity(com.klinker.android.twitter.activities.setup.LoginActivity) MainActivity(com.klinker.android.twitter.activities.MainActivity) Activity(android.app.Activity) Status(twitter4j.Status) TimelineArrayAdapter(com.klinker.android.twitter.adapters.TimelineArrayAdapter) LinearLayout(android.widget.LinearLayout)

Aggregations

Twitter (twitter4j.Twitter)127 TwitterException (twitter4j.TwitterException)76 TwitterFactory (twitter4j.TwitterFactory)60 Status (twitter4j.Status)44 Activity (android.app.Activity)35 QueryResult (twitter4j.QueryResult)17 TimelineArrayAdapter (com.klinker.android.twitter.adapters.TimelineArrayAdapter)16 Intent (android.content.Intent)13 ArrayList (java.util.ArrayList)13 User (twitter4j.User)12 Query (twitter4j.Query)11 IDs (twitter4j.IDs)8 LinearLayout (android.widget.LinearLayout)7 IOException (java.io.IOException)7 Context (android.content.Context)6 DrawerActivity (com.klinker.android.twitter.activities.drawer_activities.DrawerActivity)6 LoginActivity (com.klinker.android.twitter.activities.setup.LoginActivity)6 AppSettings (com.klinker.android.twitter.settings.AppSettings)5 GeoLocation (twitter4j.GeoLocation)5 Paging (twitter4j.Paging)5