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:project.mum.TwitterTrend.java

public List getTrends(double longi, double lati) throws TwitterException {
    List availableTrends = new ArrayList<String>();

    ConfigurationBuilder cf = new ConfigurationBuilder();
    cf.setDebugEnabled(true).setOAuthConsumerKey("TBFU8jBXiIOEde0cnSglw2m7B")
            .setOAuthConsumerSecret("c0tJVVvGgpY2rI1Ol5qmxzMpB1MiBx8PGlLNPG7TYAAVXwYVvL")
            .setOAuthAccessToken("1148852892-OR8mM62nOH4WPJf991X5bCp4zVKT2EU57fBmjWQ")
            .setOAuthAccessTokenSecret("zpXLqUxlkHZT58RDbGEPLnXVB3Kpwp7d8Z4CKb4X4UJW6");
    TwitterFactory tf = new TwitterFactory(cf.build());
    twitter4j.Twitter twitter = tf.getInstance();
    ResponseList<Location> locations;
    List<MyTrend> myTrend = new ArrayList<MyTrend>();
    MyTrend myTwitterTrend;//from  ww w .  j a  v  a 2  s.  c  o m
    GeoLocation geo = new GeoLocation(longi, lati);
    locations = twitter.getClosestTrends(geo);
    Trends trends = twitter.getPlaceTrends(locations.get(0).getWoeid());
    int count = 0;
    for (Trend trend : trends.getTrends()) {
        if (count < 5) {
            myTwitterTrend = new MyTrend(trend.getName(), trend.getURL());
            myTrend.add(myTwitterTrend);
            count++;
            availableTrends.add(trend.getName());
        }
    }
    System.out.println(" available Trends :" + availableTrends);
    return myTrend;
}

From source file:proxectotwitt.Metodo.java

/**
 * Ponemos nuestros datos para poder acceder a nuestra cuenta, codigos de twitter developers
 *//*from   w  w  w  . j  a  v a 2 s.  co m*/
public static void acceso() {

    cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true);
    cb.setOAuthConsumerKey("nipbbZAo4YYvZTiJ9eTqoweor");
    cb.setOAuthConsumerSecret("bBPcuZLVDzrhvcRYkLHgoEAy7TGgzgJtrTtYn4zL2UowgVEyHn");
    cb.setOAuthAccessToken("848794118230769664-eRC9ShFPcKgnOZh9U6hRQOSfHGISCyY");
    cb.setOAuthAccessTokenSecret("or2LmVjEXELuaRtjJSPDH1CMlQCWIH4rbPfGGMRQ9nDho");
    TwitterFactory tf = new TwitterFactory(cb.build());
    twitter = tf.getInstance();
}

From source file:proyectotwitter.AppTwitter.java

public void connect() {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("h5QMQS9cq1YDXlgBSZFOoJnkz")
            .setOAuthConsumerSecret("lCnodmJSIPHVhuxpZlnKe88TQDgwO9OGYCLpdR5gpVdKIiorCb")
            .setOAuthAccessToken("843739695091802112-z9wPdDceVHCkzQT9xgfUcPyA3scb7b6")
            .setOAuthAccessTokenSecret("1cygSjbP9gyZ0aGJep8sK2603tcZ6yaILM843nQpHdPaL");
    TwitterFactory tf = new TwitterFactory(cb.build());
    twitter = tf.getInstance();
}

From source file:samples.TwitterSentiment.java

public static twitter4j.Twitter getTwitter() {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("sB9TX9gJ9V4nB8Jh8ObKFd2FS")
            .setOAuthConsumerSecret("RPwx1Zb3DrWpqSA9g5V7GtXeidZES6xL5VnihnveSdREBA6Lgu")
            .setOAuthAccessToken("767789639843414021-3Svwm5jrJBXUkRLf0f2CAbKwSHLXH9B")
            .setOAuthAccessTokenSecret("KYUG7JbavSma9oaONPYU0ZIt1leAYFkPut75jBfWHrLTR");
    TwitterFactory tf = new TwitterFactory(cb.build());
    return tf.getInstance();

}

From source file:search.TwitterSearchBean.java

@PostConstruct
public void init() {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("tyyEHDfVKxsBqQWTeWgPkRhZd")
            .setOAuthConsumerSecret("94MPLfuaVzrWDo6RKc06MnuiJMz1yMkLvcO3wyqd6WtxIpSte0")
            .setOAuthAccessToken("169980309-qZqlDKT3XSdoki1WBmQFLHANx7QEyGxxm5tEN7gu")
            .setOAuthAccessTokenSecret("NjVrRzShxNkzyvUD5kn3KcvNvfQrelJXpzfljnSQeq9Ef");
    TwitterFactory tf = new TwitterFactory(cb.build());
    twitter = tf.getInstance();
}

From source file:sentimentanalysis.Twitter.GetTweets.java

public static void main(String args[]) {

    Twitter4JConfig t4jConfig = new Twitter4JConfig();
    ConfigurationBuilder cb = t4jConfig.getConfigurationBuilder();

    TwitterFactory tf = new TwitterFactory(cb.build());
    Twitter twitter = tf.getInstance();
    String keyword = "Trump";

    ArrayList<Post> TweetResultList = new ArrayList<Post>();
    int count = 0;
    try {// w  ww . jav  a  2s .c  o  m

        Query query = new Query(keyword + "+exclude:retweets+lang:en").until("2016-11-19");
        QueryResult result;

        do {
            result = twitter.search(query);
            ArrayList<Status> tweets = (ArrayList<Status>) result.getTweets();

            for (Status tweet : tweets) {
                count++;

                String user = tweet.getUser().getScreenName();
                String content = tweet.getText();
                Date time = tweet.getCreatedAt();
                System.out.println(time.getTime());
                String tweet_url = "https://twitter.com/" + tweet.getUser().getScreenName() + "/status/"
                        + tweet.getId();
                System.out.println(tweet.getLang());
                Post tr = new Post(user, content, tweet_url, new java.sql.Date(time.getTime()));
                TweetResultList.add(tr);

                //                    System.out.println("[user]@" + tweet.getUser().getScreenName() 
                //                        + "[/user][tweet]" + tweet.getText()+"[/tweet][link]"+tweet_url+"[/link]");
            }

        } while (((query = result.nextQuery()) != null) && (count < 500));

        try {
            SaveToDB.savePosts(TweetResultList);
        } catch (SQLException ex) {
            java.util.logging.Logger.getLogger(GetTweets.class.getName()).log(Level.SEVERE, null, ex);
        }

    } catch (TwitterException te) {
        te.printStackTrace();
    }

}

From source file:servlets.TwitterConnectionServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    System.out.println("Start TwitterConnectionServlet.doGet");

    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(UtilTwitter.CONSUMER_KEY);
    builder.setOAuthConsumerSecret(UtilTwitter.CONSUMER_SECRET);

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

    RequestToken requestToken;//www  .j  a v a2  s .  c o m

    try {
        requestToken = twitter.getOAuthRequestToken(UtilTwitter.CALL_BACK_URL);
        String url = requestToken.getAuthenticationURL();

        System.out.println("End TwitterConnectionServlet.doGet");
        response.sendRedirect(url);
    } catch (TwitterException e) {
        e.printStackTrace();
    }
}

From source file:setting.TwitterToken.java

public static Twitter twitterObject() {
    Twitter twitter = null;// ww w . j a v  a2  s .  c  om
    try {

        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true).setOAuthConsumerKey("Kb8ND2PPNcQoJSEdh2pA")
                .setOAuthConsumerSecret("vb1tSs2CRUZQUkfKDRCDAEqO1JUpSvBU7vtW3Al52IY")
                .setOAuthAccessToken("88373110-NaKga9zqHgI3t9gxWxlUQ8od8VakHtHqupLX8BKmS")
                .setOAuthAccessTokenSecret("vKp9xuT3XQWeCZ3VfgnoAeKmtqaBVB7yjpLxZJmAEgdgX");
        TwitterFactory tf = new TwitterFactory(cb.build());
        twitter = tf.getInstance();
        System.out.println(twitter);

    } catch (Exception e) {
        System.out.println(e);
    }
    return twitter;
}

From source file:Situational_Awareness.TwitterSearch.java

public TwitterSearch() {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("XQj7G52yevzl0pBkySy3UzvzR")
            .setOAuthConsumerSecret("yfsTeuPGbbX6pSvIiiOazx2E9vkuoCm1qBYT7Jvek9I5C9BPr3")
            .setOAuthAccessToken("4713593925-gOovKDZzZ5bmk6hX8CIqwmosVx6EcKQ4uxqoeVD")
            .setOAuthAccessTokenSecret("43YMSb8LRb6O7Fk0rS5vLSEzGXJ0WUCcPknpG0erSfoLb");
    TwitterFactory tf = new TwitterFactory(cb.build());
    twitter = tf.getInstance();
}

From source file:srss.core.TweetPlugin.java

License:MIT License

public TweetPlugin(Config conf) throws TwitterException {

    this.conf = conf;

    String accessTokenString = conf.getAccessToken();

    if (!accessTokenString.equals("null")) {

        TwitterFactory factory = new TwitterFactory();
        AccessToken token = new AccessToken(conf.getAccessToken(), conf.getAccessTokenSecret());

        this.twitter = factory.getInstance();
        this.twitter.setOAuthAccessToken(token);
    }/*from   ww  w.  j  av a2s  .  c  o m*/
}