Example usage for twitter4j.conf ConfigurationBuilder build

List of usage examples for twitter4j.conf ConfigurationBuilder build

Introduction

In this page you can find the example usage for twitter4j.conf ConfigurationBuilder build.

Prototype

public Configuration build() 

Source Link

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;/* ww w.  j  av  a  2 s. co  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: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  w  w  w .  ja  v a 2 s . co m
}

From source file:Recursos.Notificacion.java

/**
 * Constructor de la clase Notificacion//from  w w  w .  j a  v a2  s . c o  m
 *
 * inicializa todos los medios para hacer la coneccion de la cuenta del
 * twitter conn la aplicaccion
 */
public Notificacion() {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setOAuthConsumerKey("STFH7e9yQ8K7pIgs7oZSmsUB8");
    cb.setOAuthConsumerSecret("6Uj5BMITSyd17UNFxTLi47k39KkOMuwIszCgXkc8AC3mNJEp3U");
    cb.setOAuthAccessToken("133844036-u3qdbqgsxlSMeNWa5NzFrSCbnjAI7ExrRDHFrWw9");
    cb.setOAuthAccessTokenSecret("5m7rBhbEQmll0bGtPGC3sqE3mo3emjmrjKrCBg26t9jhG");

    twitter = new TwitterFactory(cb.build()).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 w  ww  . j  a  v  a2  s .c  om
}

From source file:SentimentAnalyses.PrintSampleStream.java

License:Apache License

public static void main(String[] args) throws TwitterException {

    final PrintSampleStream pr = new PrintSampleStream();

    try {//from www . ja  v  a2 s. com
        pr.LinkMongodb();
    } catch (Exception e) {
        e.printStackTrace();
    }

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("Em3WTI7jc90HcvKzPkTLQ")
            .setOAuthConsumerSecret("vg4p6rOF32bmffqRR8m0jAUClrxvtGiMB5PrSr3Zsw")
            .setOAuthAccessToken("1681973072-1q0zI0VPjHD3ttNuaBOL94frzCI9sXInxAcDK0w")
            .setOAuthAccessTokenSecret("ZRLkOyjmhHBkU1iNyEVNyIgIBsKrl0DUDKOcOMneYFYEM");
    cb.setJSONStoreEnabled(true);

    TwitterStreamFactory tf = new TwitterStreamFactory(cb.build());
    TwitterStream twitterStream = tf.getInstance();
    StatusListener listener = new StatusListener() {
        @Override
        public void onStatus(Status status) {
            //System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
            //System.out.println(status);
            String str = DataObjectFactory.getRawJSON(status);
            try {
                //JSONObject nnstr = new JSONObject(newstr);
                DBObject dbObject = (DBObject) JSON.parse(str);
                //                    System.out.println(dbObject);
                pr.collection.insert(dbObject);
                //System.out.println(dbObject);
                pr.count++;
                if (pr.count % 1000 == 0)
                    System.out.println(pr.count);
                if (pr.count > 100000) {
                    pr.mongo.close();
                    System.exit(0);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
            System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
        }

        @Override
        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
            System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
        }

        @Override
        public void onScrubGeo(long userId, long upToStatusId) {
            System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
        }

        @Override
        public void onStallWarning(StallWarning warning) {
            System.out.println("Got stall warning:" + warning);
        }

        @Override
        public void onException(Exception ex) {
            ex.printStackTrace();
        }
    };
    twitterStream.addListener(listener);

    String[] trackArray;
    String[] Track = { "Malaysia Airlines", "Flight MH370", "Boeing-777", "Kuala Lumpur", "Bei jing" };
    //trackArray[0] = "Obama";
    //trackArray[1] = "Romney";

    FilterQuery filter = new FilterQuery();
    filter.track(Track);
    String[] lang = { "en" };
    filter.language(lang);
    twitterStream.filter(filter);
    //pr.mongo.close();
}

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();/*from  w  ww  .  java2s .com*/
    String keyword = "Trump";

    ArrayList<Post> TweetResultList = new ArrayList<Post>();
    int count = 0;
    try {

        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:Servlet.TwitterAuthServlet.java

License:Apache License

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
 *
 * @param request servlet request//from ww w. j  a  v a  2s .  c o  m
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");

    ConfigurationBuilder cb = new ConfigurationBuilder();

    cb.setOAuthConsumerKey(TwitterApp.CONSUMER_KEY);
    cb.setOAuthConsumerSecret(TwitterApp.CONSUMER_SECRET);

    Twitter twitter = new TwitterFactory(cb.build()).getInstance();
    request.getSession().setAttribute("twitter", twitter);
    try {
        StringBuffer callbackURL = request.getRequestURL();
        int index = callbackURL.lastIndexOf("/");
        callbackURL.replace(index, callbackURL.length(), "").append("/callback");

        System.out.println(callbackURL);

        RequestToken requestToken = twitter.getOAuthRequestToken(callbackURL.toString());

        System.out.println("Authentication " + requestToken.getAuthenticationURL());
        System.out.println("Authorization " + requestToken.getAuthorizationURL());

        request.getSession().setAttribute("requestToken", requestToken);
        response.sendRedirect(requestToken.getAuthenticationURL());
    } catch (TwitterException e) {
        throw new ServletException(e);
    }
}

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;/*  w w w. ja  v  a2  s  .com*/

    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;//from   ww w  . j a v  a  2s  .  c o  m
    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;
}