Example usage for twitter4j TwitterFactory getInstance

List of usage examples for twitter4j TwitterFactory getInstance

Introduction

In this page you can find the example usage for twitter4j TwitterFactory getInstance.

Prototype

public Twitter getInstance() 

Source Link

Document

Returns a instance associated with the configuration bound to this factory.

Usage

From source file:OAuth.MyOwnTwitterFactory.java

License:Open Source License

public Twitter createOneTwitterInstance() {
    Twitter twitter;/*from   ww w .j av  a2  s. c o  m*/
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(APIkeys.getTwitterAPIKey());
    builder.setOAuthConsumerSecret(APIkeys.getTwitterAPISecret());
    builder.setOAuthAccessToken("31805620-QQy8TFFDKRxWyOUVnY08UcxT5bzrFhRWUa0A3lEW3");
    builder.setOAuthAccessTokenSecret("iJuCkdgrfIpGn5odyF2evMSvAsovreeEV6cZU5ihVVI7j");
    Configuration configuration = builder.build();
    TwitterFactory factory = new TwitterFactory(configuration);
    twitter = factory.getInstance();

    return twitter;

}

From source file:onl.area51.a51li.twitter.TwitterAccount.java

License:Apache License

public TwitterAccount(int id, String account, String token, String secret, TwitterApplication application) {
    this.id = id;
    this.account = account;
    this.token = token;
    this.secret = secret;

    ConfigurationBuilder cb = new ConfigurationBuilder().setOAuthConsumerKey(application.getKey())
            .setOAuthConsumerSecret(application.getSecret()).setOAuthAccessToken(token)
            .setOAuthAccessTokenSecret(secret);

    TwitterFactory f = new TwitterFactory(cb.build());
    twitter = f.getInstance();
}

From source file:ontoSentiment.Amigos.java

@Override
public void run() {
    ConfigurationBuilder cb = new ConfigurationBuilder();

    //the following is set without accesstoken- desktop client
    cb.setDebugEnabled(true).setOAuthConsumerKey("FBd5n7dyl8mCz73qyfZ0p4XHb")
            .setOAuthConsumerSecret("vu5Xt5TzBSL9naOZylIYlx5MdcRlhH2LvkpW6KIkxSf9AqwuGt")
            .setOAuthAccessToken("3232400175-lAchtC6ChWMTnJKe3BaWbst8SucIaTjn5gm4Rp2")
            .setOAuthAccessTokenSecret("DnkquBWAS6igYpM8Z4r54hH7ztcfMX6u8OzMXBLwM9Xkh");

    try {//w ww  . j  ava2s.  co  m
        TwitterFactory tf = new TwitterFactory(cb.build());
        Twitter twitter = tf.getInstance();

        //User u = twitter.showUser("karlaffabiola");            
        User u = twitter.showUser("raythemaster");
        IDs ids;
        System.out.println("Listing followers's ids.");

        System.out.println("ID: " + u.getId());
        System.out.println("Nome: " + u.getScreenName());

        long cursor = -1;
        PagableResponseList<User> pagableFollowings;
        List<User> listFriends = new ArrayList<>();
        List<User> listFriends2 = new ArrayList<>();

        pagableFollowings = twitter.getFriendsList(u.getId(), cursor, 200);
        System.out.println("Qunatidade followers: " + pagableFollowings.size());
        for (User user : pagableFollowings) {
            System.out.println("Id: " + user.getId() + " Nome: " + user.getScreenName());
            listFriends.add(user); // ArrayList<User>
        }

        for (User user : listFriends) {
            System.out.println("Id1: " + user.getId() + " Nome1: " + user.getScreenName());
            pagableFollowings = twitter.getFriendsList(user.getId(), cursor, 200);
            System.out.println("Qunatidade followers: " + pagableFollowings.size());
            for (User user2 : pagableFollowings) {
                System.out.println("Id2: " + user2.getId() + " Nome2: " + user2.getScreenName());
                listFriends2.add(user2); // ArrayList<User>
            }
        }
        System.out.println("Lista 1:" + listFriends.size());
        System.out.println("Lista 2:" + listFriends2.size());
        System.exit(0);
    } catch (TwitterException te) {
        // te.printStackTrace();
        System.out.println("Failed to get timeline: " + new Date());
        try {
            Thread.sleep(3 * 60 * 1000);
            run();
        } catch (InterruptedException ex) {
            Logger.getLogger(Amigos.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:org.apache.asterix.external.util.TwitterUtil.java

License:Apache License

public static Twitter getTwitterService(Map<String, String> configuration) {
    ConfigurationBuilder cb = getAuthConfiguration(configuration);
    TwitterFactory tf = null;
    try {//  w  ww  . j  a  v a2 s  .  c  o  m
        tf = new TwitterFactory(cb.build());
    } catch (Exception e) {
        if (LOGGER.isLoggable(Level.WARNING)) {
            StringBuilder builder = new StringBuilder();
            builder.append("Twitter Adapter requires the following config parameters\n");
            builder.append(AuthenticationConstants.OAUTH_CONSUMER_KEY + "\n");
            builder.append(AuthenticationConstants.OAUTH_CONSUMER_SECRET + "\n");
            builder.append(AuthenticationConstants.OAUTH_ACCESS_TOKEN + "\n");
            builder.append(AuthenticationConstants.OAUTH_ACCESS_TOKEN_SECRET + "\n");
            LOGGER.warning(builder.toString());
            LOGGER.warning(
                    "Unable to configure Twitter adapter due to incomplete/incorrect authentication credentials");
            LOGGER.warning(
                    "For details on how to obtain OAuth authentication token, visit https://dev.twitter.com/oauth/overview/application-owner-access-tokens");
        }
    }
    Twitter twitter = tf.getInstance();
    return twitter;
}

From source file:org.apache.nutch.protocol.http.api.HttpBase.java

License:Apache License

private Twitter getTwitterInstance(String consumerKey, String consumerSecret, String accessToken,
        String accessTokenSecret) {
    TwitterFactory tf = getTwitterFactoryWithConfigParams(consumerKey, consumerSecret, accessToken,
            accessTokenSecret);/*from  ww  w. ja  v a  2s .  c o m*/

    Twitter twitter = tf.getInstance();
    return twitter;
}

From source file:org.apparatus_templi.service.TwitterService.java

License:Open Source License

private void start() {
    accessToken = Coordinator.getPrefs().getPreference(Prefs.Keys.twtrAccess);
    accessTokenKey = Coordinator.getPrefs().getPreference(Prefs.Keys.twtrAccessKey);
    if (accessToken != null && accessTokenKey != null) {
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true).setOAuthConsumerKey(CONSUMER_KEY).setOAuthConsumerSecret(CONSUMER_SECRET)
                .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessTokenKey);
        TwitterFactory tf = new TwitterFactory(cb.build());
        twitter = tf.getInstance();
    } else {//from   w  w  w. jav  a2  s .  c  o  m
        Log.e(TAG, "Twitter service requires authentication for a particular user account.");
    }
}

From source file:org.brunocvcunha.taskerbox.impl.twitter.TwitterChannel.java

License:Apache License

@Override
public void setup() throws IllegalStateException, TwitterException {
    logInfo(log, "Twitter setup...");

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey(this.consumerKey).setOAuthConsumerSecret(this.consumerSecret)
            .setOAuthAccessToken(this.accessToken).setOAuthAccessTokenSecret(this.accessTokenSecret);
    TwitterFactory tf = new TwitterFactory(cb.build());

    this.twitter = tf.getInstance();

    this.loggedUser = this.twitter.getScreenName();

    logInfo(log, "Twitter setup finished! Logged user is " + this.loggedUser);
}

From source file:org.craftercms.cstudio.publishing.processor.TwitterPostProcessor.java

License:Open Source License

/**
 * factory method for twitter instance. Override if you want to authenticate differently
 * @return twitter instance/*  w  w  w.j av a  2 s.co m*/
 */
protected Twitter getTwitterInstance() {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setDebugEnabled(true).setOAuthConsumerKey(consumerKeyStr).setOAuthConsumerSecret(consumerSecretStr)
            .setOAuthAccessToken(accessTokenStr).setOAuthAccessTokenSecret(accessTokenSecretStr);

    Configuration configuration = builder.build();
    TwitterFactory factory = new TwitterFactory(configuration);
    Twitter twitter = factory.getInstance();

    return twitter;
}

From source file:org.encuestame.social.api.templates.TwitterAPITemplate.java

License:Apache License

/**
 * Get OAuthorized Token.//  w w w.  j  ava 2  s  .  c om
 * @param socialTwitterAccount {@link SocialAccount}.
 * @return {@link Twitter}.
 */
private Twitter getOAuthAuthorizedInstance() {
    final TwitterFactory tf = new TwitterFactory(this.configurationBuilder.build());
    final Twitter twitter = tf.getInstance();
    return twitter;
}

From source file:org.examproject.tweet.service.SimpleTweetService.java

License:Apache License

private Twitter getTwitter() {
    TwitterFactory factory = new TwitterFactory();
    Twitter twitter = factory.getInstance();
    twitter.setOAuthConsumer(authValue.getConsumerKey(), authValue.getConsumerSecret());
    twitter.setOAuthAccessToken(new AccessToken(authValue.getOauthToken(), authValue.getOauthTokenSecret()));
    return twitter;
}