Example usage for twitter4j.conf ConfigurationBuilder setDebugEnabled

List of usage examples for twitter4j.conf ConfigurationBuilder setDebugEnabled

Introduction

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

Prototype

public ConfigurationBuilder setDebugEnabled(boolean debugEnabled) 

Source Link

Usage

From source file:org.kawalpemilukada.login.login.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./* w  w w  .j  av a 2 s  . com*/
 *
 * @param request servlet request
 * @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 {
    String form_action = request.getParameter("form_action");
    if (form_action == null) {
        form_action = "";
    }
    PrintWriter out = response.getWriter();
    if (form_action.equalsIgnoreCase("loginfb")) {
        String tahun = request.getParameter("tahun");
        if (tahun == null) {
            tahun = "";
        }
        Facebook facebook = new FacebookFactory().getInstance();
        request.getSession().setAttribute("facebook", facebook);
        request.getSession().setAttribute("tahun", tahun);
        StringBuffer callbackURL = request.getRequestURL();
        int index = callbackURL.lastIndexOf("/");
        callbackURL.replace(index, callbackURL.length(), "").append("/callbackfb");
        response.sendRedirect(facebook.getOAuthAuthorizationURL(callbackURL.toString()) + "&display=popup");
    }
    if (form_action.equalsIgnoreCase("logintwit")) {
        String tahun = request.getParameter("tahun");
        if (tahun == null) {
            tahun = "";
        }
        Twitter twitter = new TwitterFactory().getInstance();
        request.getSession().setAttribute("twitter", twitter);
        request.getSession().setAttribute("tahun", tahun);
        String rurl = request.getParameter("rurl");
        StringBuffer callbackURL = request.getRequestURL();
        int index = callbackURL.lastIndexOf("/");
        callbackURL.replace(index, callbackURL.length(), "").append("/callbackTwit?rurl=" + rurl);
        try {
            RequestToken requestToken = twitter.getOAuthRequestToken(callbackURL.toString());
            request.getSession().setAttribute("requestToken", requestToken);
            response.sendRedirect(requestToken.getAuthenticationURL());
        } catch (TwitterException e) {
            request.getSession().removeAttribute("twitter");
            request.getSession().removeAttribute("tahun");
        }
    }

    if (form_action.equalsIgnoreCase("loginmobiletwit")) {
        String t = "twit";
        UserData user = CommonServices.getUser(request);
        LinkedHashMap record = new LinkedHashMap();
        Gson gson = new Gson();
        StringBuffer sb = new StringBuffer();
        String line = null;
        BufferedReader reader = request.getReader();
        while ((line = reader.readLine()) != null) {
            sb.append(line);
        }
        JSONObject input = (JSONObject) JSONValue.parse(sb.toString());
        if (user == null) {
            try {
                JSONObject twit = (JSONObject) input.get("user");
                String id = CommonServices.getVal(twit.get("id"));
                id = id.replaceAll(t, "");
                user = ofy().load().type(UserData.class).id(t + id).now();
                if (user == null) {
                    String accessToken = CommonServices.getVal(twit.get("token"));
                    String accessTokenSecret = CommonServices.getVal(twit.get("secret"));
                    String consumerKey = new CommonServices().getPropValues("kpu.properties", "consumerKey",
                            request);
                    String consumerSecret = new CommonServices().getPropValues("kpu.properties",
                            "consumerSecret", request);
                    ConfigurationBuilder cb = new ConfigurationBuilder();
                    cb.setDebugEnabled(true).setOAuthConsumerKey(consumerKey)
                            .setOAuthConsumerSecret(consumerSecret).setOAuthAccessToken(accessToken)
                            .setOAuthAccessTokenSecret(accessTokenSecret);
                    Twitter twitter = new TwitterFactory(cb.build()).getInstance();
                    User u = twitter.showUser(twitter.getId());
                    user = new UserData("twit" + CommonServices.getVal(twitter.getId()));
                    user.imgurl = u.getBiggerProfileImageURLHttps().replace("http://", "https://");
                    user.nama = CommonServices.getVal(u.getName());
                    user.link = "https://twitter.com/" + CommonServices.getVal(twitter.getScreenName());
                    user.email = "";
                    user.uuid = CommonServices.getVal(twit.get("uuid"));
                    user.type = t;
                    ofy().save().entity(user).now();
                    Dashboard dashboard = CommonServices.getDashboard(CommonServices.setParentId("2015", "0"));
                    Dashboard dashboard2014 = CommonServices
                            .getDashboard(CommonServices.setParentId("2014", "0"));
                    dashboard.users = CommonServices.getuserSize() + "";
                    ofy().save().entity(dashboard).now();
                    dashboard2014.users = dashboard.users + "";
                    ofy().save().entity(dashboard2014).now();
                } else {
                    user.lastlogin = CommonServices.JakartaTime();
                    user.uuid = CommonServices.getVal(twit.get("uuid"));
                    if (user.link.equalsIgnoreCase("https://twitter.com/kawalpemilukada")
                            || user.link.equalsIgnoreCase(
                                    "https://www.facebook.com/app_scoped_user_id/10153164750839760/")) {
                        user.userlevel = 100000000;
                    }
                    ofy().save().entity(user).now();
                }
                request.getSession().setAttribute("UserData", JSONValue.parse(gson.toJson(user)));
                MobileSession mobileSession = new MobileSession(user.uid + "#" + user.uuid);
                JSONObject device = (JSONObject) input.get("device");
                mobileSession.platform = CommonServices.getVal(device.get("platform"));
                mobileSession.version = CommonServices.getVal(device.get("version"));
                mobileSession.cordova = CommonServices.getVal(device.get("cordova"));
                mobileSession.model = CommonServices.getVal(device.get("model"));
                mobileSession.manufacturer = CommonServices.getVal(device.get("manufacturer"));
                mobileSession.appversion = CommonServices.getVal(device.get("appversion"));
                ofy().save().entity(mobileSession).now();
                record.put("sessionid", mobileSession.uuid);
            } catch (Exception e) {
            }
            record.put("sumber", "bukan dari session");
        } else {
            MobileSession mobileSession = new MobileSession(user.uid + "#" + user.uuid);
            JSONObject device = (JSONObject) input.get("device");
            mobileSession.platform = CommonServices.getVal(device.get("platform"));
            mobileSession.version = CommonServices.getVal(device.get("version"));
            mobileSession.cordova = CommonServices.getVal(device.get("cordova"));
            mobileSession.model = CommonServices.getVal(device.get("model"));
            mobileSession.manufacturer = CommonServices.getVal(device.get("manufacturer"));
            mobileSession.appversion = CommonServices.getVal(device.get("appversion"));
            ofy().save().entity(mobileSession).now();
            record.put("sessionid", mobileSession.uuid);
            record.put("sumber", "dari session");
        }
        record.put("user", JSONValue.parse(gson.toJson(user)));
        response.setContentType("text/html;charset=UTF-8");
        out.print(JSONValue.toJSONString(record));
        out.flush();
    }
    if (form_action.equalsIgnoreCase("loginmobilefb")) {
        UserData user = CommonServices.getUser(request);
        LinkedHashMap record = new LinkedHashMap();
        Gson gson = new Gson();
        StringBuffer sb = new StringBuffer();
        String line = null;
        BufferedReader reader = request.getReader();
        while ((line = reader.readLine()) != null) {
            sb.append(line);
        }
        JSONObject input = (JSONObject) JSONValue.parse(sb.toString());
        if (user == null) {
            String t = "fb";
            JSONObject fb = (JSONObject) input.get("user");
            String id = CommonServices.getVal(fb.get("id"));
            id = id.replaceAll(t, "");
            try {
                user = ofy().load().type(UserData.class).id(t + id).now();
                if (user == null) {
                    user = new UserData("fb" + CommonServices.getVal(fb.get("id")));
                    user.imgurl = "https://graph.facebook.com/" + fb.get("id") + "/picture";
                    user.nama = CommonServices.getVal(fb.get("name"));
                    user.link = CommonServices.getVal(fb.get("link"));
                    user.email = CommonServices.getVal(fb.get("email"));
                    user.type = t;
                    user.uuid = CommonServices.getVal(fb.get("uuid"));
                    ofy().save().entity(user).now();
                    Dashboard dashboard = CommonServices.getDashboard(CommonServices.setParentId("2015", "0"));
                    Dashboard dashboard2014 = CommonServices
                            .getDashboard(CommonServices.setParentId("2014", "0"));
                    dashboard.users = CommonServices.getuserSize() + "";
                    ofy().save().entity(dashboard).now();
                    dashboard2014.users = dashboard.users + "";
                    ofy().save().entity(dashboard2014).now();
                } else {
                    user.lastlogin = CommonServices.JakartaTime();
                    user.uuid = CommonServices.getVal(fb.get("uuid"));
                    if (user.link.equalsIgnoreCase("https://twitter.com/kawalpemilukada")
                            || user.link.equalsIgnoreCase(
                                    "https://www.facebook.com/app_scoped_user_id/10153164750839760/")) {
                        user.userlevel = 100000000;
                    }
                    ofy().save().entity(user).now();
                }
                request.getSession().setAttribute("UserData", JSONValue.parse(gson.toJson(user)));
                MobileSession mobileSession = new MobileSession(user.uid + "#" + user.uuid);
                JSONObject device = (JSONObject) input.get("device");
                mobileSession.platform = CommonServices.getVal(device.get("platform"));
                mobileSession.version = CommonServices.getVal(device.get("version"));
                mobileSession.cordova = CommonServices.getVal(device.get("cordova"));
                mobileSession.model = CommonServices.getVal(device.get("model"));
                mobileSession.manufacturer = CommonServices.getVal(device.get("manufacturer"));
                mobileSession.appversion = CommonServices.getVal(device.get("appversion"));
                ofy().save().entity(mobileSession).now();
                record.put("sessionid", mobileSession.uuid);
            } catch (Exception e) {
            }
            record.put("sumber", "bukan dari session");
        } else {
            record.put("sumber", "dari session");
            MobileSession mobileSession = new MobileSession(user.uid + "#" + user.uuid);
            JSONObject device = (JSONObject) input.get("device");
            mobileSession.platform = CommonServices.getVal(device.get("platform"));
            mobileSession.version = CommonServices.getVal(device.get("version"));
            mobileSession.cordova = CommonServices.getVal(device.get("cordova"));
            mobileSession.model = CommonServices.getVal(device.get("model"));
            mobileSession.manufacturer = CommonServices.getVal(device.get("manufacturer"));
            mobileSession.appversion = CommonServices.getVal(device.get("appversion"));
            ofy().save().entity(mobileSession).now();
            record.put("sessionid", mobileSession.uuid);
        }
        record.put("user", JSONValue.parse(gson.toJson(user)));
        response.setContentType("text/html;charset=UTF-8");
        out.print(JSONValue.toJSONString(record));
        out.flush();
    }
    if (form_action.equalsIgnoreCase("cekauth")) {
        UserData user = CommonServices.getUser(request);
        LinkedHashMap record = new LinkedHashMap();
        Gson gson = new Gson();
        if (user == null) {
            record.put("status", "belum login");
        } else {
            record.put("user", JSONValue.parse(gson.toJson(user)));
            if (user.terverifikasi.equalsIgnoreCase("Y")) {
                record.put("status", "terverifikasi");
            } else {
                record.put("status", "Data Anda belum terverifikasi.");
            }
        }
        response.setContentType("text/html;charset=UTF-8");
        out.print(JSONValue.toJSONString(record));
        out.flush();
    }
    if (form_action.equalsIgnoreCase("verifikasi")) {
        LinkedHashMap record = new LinkedHashMap();
        StringBuffer sb = new StringBuffer();
        String line = null;
        BufferedReader reader = request.getReader();
        while ((line = reader.readLine()) != null) {
            sb.append(line);
        }
        JSONArray input = (JSONArray) JSONValue.parse(sb.toString());
        String nama = "";
        String jenis_kelamin = "";
        String no_tps = "";
        try {
            String url = new CommonServices().getPropValues("kpu.properties", "verifikasiURL", request);
            String inputx = getWeb(url + input.get(0).toString());
            JSONObject data = (JSONObject) JSONValue.parse(inputx);
            nama = data.get("nama").toString();
            jenis_kelamin = data.get("jenis_kelamin").toString();
        } catch (Exception e) {
            nama = "";
        }
        if (nama == null || nama.equalsIgnoreCase("")) {
            try {
                String url = new CommonServices().getPropValues("kpu.properties", "verifikasiURL2015", request);
                String inputx = getWeb(url + input.get(0).toString());
                LinkedHashMap data = getJsonNik(inputx);
                nama = data.get("nama").toString();
                jenis_kelamin = data.get("jenis kelamin").toString();
                no_tps = data.get("no_tps").toString();
            } catch (Exception e) {
                nama = "";
            }
        }
        JSONArray matchs = new JSONArray();
        if (nama.equalsIgnoreCase(input.get(1).toString())) {
            UserData user = CommonServices.getUser(request);
            double match = 0;
            //if (data.get("nama").toString().equalsIgnoreCase(user.nama)) {
            //match = 100;
            //} else {
            String[] sosialnamaParts = user.nama.toString().split(" ");
            String[] namaParts = nama.toString().split(" ");
            int dibagi = sosialnamaParts.length;
            if (namaParts.length > dibagi) {
                dibagi = namaParts.length;
            }
            double increase = 100 / dibagi;
            String iiString = "";
            for (int i = 0; i < namaParts.length; i++) {
                String namaPart = namaParts[i];
                for (int ii = 0; ii < sosialnamaParts.length; ii++) {
                    String fbnamaPart = sosialnamaParts[ii];
                    if (namaPart.equalsIgnoreCase(fbnamaPart) && (!iiString.contains(ii + ""))) {
                        match = match + increase;
                        matchs.add(namaPart + " sesuai dengan " + fbnamaPart);
                        iiString = iiString + "[" + ii + "]";
                        break;
                    }
                }
            }
            // }
            if (match > 100) {
                match = 100;
            }
            if (match >= 60) {
                user.terverifikasi = "Y";
                user.notps = no_tps;
                ObjectifyService.ofy().save().entity(user).now();
                Gson gson = new Gson();
                record.put("user", JSONValue.parse(gson.toJson(user)));
            }
            record.put("status", match + "");
            record.put("matchs", matchs);
        } else {
            record.put("status", "Data NIK: " + input.get(0).toString() + " dan Nama: "
                    + input.get(1).toString() + " tidak ditemukan.");
        }
        response.setContentType("text/html;charset=UTF-8");
        out.print(JSONValue.toJSONString(record));
        out.flush();
    }
}

From source file:org.keycloak.examples.broker.twitter.TwitterShowUserServlet.java

License:Apache License

@Override
protected void doGet(final HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    TwitterOAuthResponse twitterOAuthResponse = getTwitterOAuthResponse(request);
    ConfigurationBuilder cb = new ConfigurationBuilder();

    cb.setDebugEnabled(true).setOAuthConsumerKey(this.identityProvider.getConfig().get("clientId"))
            .setOAuthConsumerSecret(this.identityProvider.getConfig().get("clientSecret"))
            .setOAuthAccessToken(twitterOAuthResponse.getToken())
            .setOAuthAccessTokenSecret(twitterOAuthResponse.getTokenSecret());

    TwitterFactory tf = new TwitterFactory(cb.build());
    Twitter twitter = tf.getInstance();/*from  ww  w .ja  v a  2  s . com*/

    try {
        User user = twitter.users().showUser(twitterOAuthResponse.getScreenName());

        response.setContentType(MediaType.APPLICATION_JSON);

        PrintWriter writer = response.getWriter();

        writer.println(new ObjectMapper().writeValueAsString(user));

        writer.flush();
    } catch (TwitterException e) {
        throw new RuntimeException("Could not load social profile.", e);
    }
}

From source file:org.manalith.ircbot.plugin.tweetreader.TweetReader.java

License:Open Source License

private void initTwitter4j() throws TwitterException {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    Configuration config = builder.setDebugEnabled(false).setJSONStoreEnabled(true)
            .setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret).build();

    tweet = new TwitterFactory(config).getInstance();
    requestToken = tweet.getOAuthRequestToken();
}

From source file:org.mixare.utils.TwitterClient.java

License:Open Source License

/**
 * Query the twitter search API using oAuth 2.0
 * @return//from   www  .  ja v a2  s  .  c  om
 */
public static String queryData() {
    ConfigurationBuilder cb = new ConfigurationBuilder(); //to be configured in a properties...
    cb.setDebugEnabled(true).setOAuthConsumerKey("mt10dv6tTKacqlm14lw5w")
            .setOAuthConsumerSecret("4kRV1E1XIU3kj4JQj2R5LE1yct0RRaRl9sB5PpPrB0")
            .setOAuthAccessToken("390019380-IQ5VdvUKvxY9JOsTToEU8ElCabebc76H9X2g3QX4")
            .setOAuthAccessTokenSecret("ghJn4LTfDr7uHUCsbt6ycmpeVTwwpa3hZnXyEjyZvs");
    cb.setJSONStoreEnabled(true);

    TwitterFactory tf = new TwitterFactory(cb.build());
    Twitter twitter = tf.getInstance();

    Query query = new Query();
    query = query.geoCode(new GeoLocation(lat, lon), rad, Query.KILOMETERS);

    String jsonArrayAsString = "{\"results\":[";//start
    try {
        QueryResult result = twitter.search(query);
        int size = 0;
        for (Status status : result.getTweets()) {
            {
                if (status.getGeoLocation() != null) {
                    String jsonSingleObject = DataObjectFactory.getRawJSON(status);
                    if (size == 0)
                        jsonArrayAsString += jsonSingleObject;
                    else
                        jsonArrayAsString += "," + jsonSingleObject;
                    size++;
                }
            }
        }
        jsonArrayAsString += "]}";//close array
        return jsonArrayAsString;
    } catch (Exception e) {
        Log.e(Config.TAG, "Error querying twitter data :" + e);
        e.printStackTrace();
    }
    return null;
}

From source file:org.opensocial.TwitterProxy.java

License:Apache License

public TwitterProxy() {
    ConfigurationBuilder cb = new ConfigurationBuilder();

    Properties props = new Properties();
    try {/* w  ww.  j  a v a 2  s .  co  m*/
        InputStream is = TwitterProxy.class.getClassLoader().getResourceAsStream("TwitterProxy.properties");
        props.load(is);
        cb.setDebugEnabled(true).setOAuthConsumerKey(props.getProperty("oauth_key"))
                .setOAuthConsumerSecret(props.getProperty("oauth_secret"))
                .setOAuthAccessToken(props.getProperty("oauth_access_token"))
                .setOAuthAccessTokenSecret(props.getProperty("oauth_access_token_secret"));
    } catch (IOException e) {
        e.printStackTrace();
    }
    tf = new TwitterFactory(cb.build());
    twitter = tf.getInstance();
}

From source file:org.ow2.frascati.akka.fabric.peakforecast.lib.TwitterImpl.java

License:Open Source License

@Override
public void updateStatus(String message) {
    try {//from  w  w w  .  ja  v  a 2s . c  om

        ConfigurationBuilder cb = new ConfigurationBuilder();
        //info OAuth settings de l'application twitter tweetpeakforecast enregistr par l'utilisateur @peakforecast 
        cb.setDebugEnabled(true).setOAuthConsumerKey("0PqersXnGOn7AirB13jszw")
                .setOAuthConsumerSecret("r3qyCuhmwRI90JY04kqcYtn5yEl6yaW1UoRhAY08Q")
                .setOAuthAccessToken("1598158057-epoKcN3Lfz405zjNZQ2rl5cx74lthvBZ93cCsfj")
                .setOAuthAccessTokenSecret("6YwDPdjS7OpqDHb6PsmW0beOjCgjITzDGYV89gtQU");
        TwitterFactory tf = new TwitterFactory(cb.build());
        Twitter twitter = tf.getInstance();
        Status status = twitter.updateStatus(message);
        System.out.println("Successfully updated the status to [" + status.getText() + "].");

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.rapidpm.book.iot.tinkerforge.twitter.TwitterFactory.java

License:Apache License

public TwitterFactory() {
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("DI0UZvexwirEJ1wl5sw9Vfqx3")
            .setOAuthConsumerSecret("NQ0Zumw7Li1XbuwzrNHOKquznBgmAJo1sPAoqiNMShqgFufqip")
            .setOAuthAccessToken("2440296835-4dmuWPOLYUgLjn9ddcXpuloOgDAPO1W0Y5NZSg7")
            .setOAuthAccessTokenSecret("X9QYzlDKURIxGZbFWoZ7NdvhcFurBfEUVHMTLxtBSrU2x");
    tf = new twitter4j.TwitterFactory(cb.build());
}

From source file:org.selman.tweetamo.TweetamoClient.java

License:Apache License

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

    if (args.length != 2) {
        System.out.println("Usage: [language] [search topic]");
    }/*from www  .j a  va 2s . c  om*/

    kinesisClient = new AmazonKinesisClient(new ClasspathPropertiesFileCredentialsProvider());
    waitForStreamToBecomeAvailable(STREAM_NAME);

    LOG.info("Publishing tweets to stream : " + STREAM_NAME);
    StatusListener listener = new StatusListener() {
        public void onStatus(Status status) {
            try {
                PutRecordRequest putRecordRequest = new PutRecordRequest();
                putRecordRequest.setStreamName(STREAM_NAME);
                putRecordRequest.setData(TweetSerializer.toBytes(status));
                putRecordRequest.setPartitionKey(status.getUser().getScreenName());
                PutRecordResult putRecordResult = kinesisClient.putRecord(putRecordRequest);
                LOG.info("Successfully putrecord, partition key : " + putRecordRequest.getPartitionKey()
                        + ", ShardID : " + putRecordResult.getShardId());

            } catch (Exception e) {
                LOG.error("Failed to putrecord", e);
            }
        }

        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
        }

        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
        }

        public void onException(Exception ex) {
            ex.printStackTrace();
        }

        @Override
        public void onScrubGeo(long arg0, long arg1) {
        }

        @Override
        public void onStallWarning(StallWarning arg0) {
        }
    };

    ClasspathTwitterCredentialsProvider provider = new ClasspathTwitterCredentialsProvider();
    TwitterCredentials credentials = provider.getTwitterCredentials();

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey(credentials.getConsumerKey())
            .setOAuthConsumerSecret(credentials.getConsumerSecret())
            .setOAuthAccessToken(credentials.getAccessToken())
            .setOAuthAccessTokenSecret(credentials.getAccessTokenSecret());
    TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
    twitterStream.addListener(listener);
    FilterQuery filterQuery = new FilterQuery();
    filterQuery.language(new String[] { args[0] });
    filterQuery.track(new String[] { args[1] });
    twitterStream.filter(filterQuery);
}

From source file:org.smarttechie.servlet.SimpleStream.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String keywords = request.getParameter("keywords");
    SEARCH_NAME = request.getParameter("SearchName");
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true);
    cb.setOAuthConsumerKey("Y8NvcZqWjUvNR0wfict2rSKmx");
    cb.setOAuthConsumerSecret("A3K8YqVjLpTN5sSbk9MJ8DmiwIxRapLmyhmZcCau55sqzPjA1y");
    cb.setOAuthAccessToken("566064066-BMF8JBt2JI7c4KBWEDtxRqPN2rLNxwKcUoykzoTR");
    cb.setOAuthAccessTokenSecret("wo4LnwlsYYfbYkGixN0CS3NxlYfXxbxwl0gWfpQTIKas4");
    //PrintStream out = new PrintStream(new FileOutputStream("/home/mary/Documents/Tesis/output.txt"));
    //System.setOut(out);
    Cluster cluster;/*from w ww.ja v a2  s .  c  o  m*/
    Session session;
    cluster = Cluster.builder().addContactPoint("localhost").build();
    session = cluster.connect("GetTheLead");
    String[] parametros = { keywords };
    twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
    //EmbeddedNeo4j neo = new EmbeddedNeo4j();
    //neo.createDb();
    //neo.removeData();
    //neo.shutDown();
    graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
    registerShutdownHook(graphDb);
    getStream(twitterStream, parametros, session);//,out);
    //out.close();

}

From source file:org.smarttechie.servlet.TwitterLoginServlet.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    System.out.println("TwitterLoginServlet:doGet");
    ConfigurationBuilder cb = new ConfigurationBuilder();

    Properties props = new TwitterProperties().getProperties();
    cb.setDebugEnabled(true).setOAuthConsumerKey((String) props.get("twitterConsumerKey"))
            .setOAuthConsumerSecret((String) props.get("twitterConsumerSecret"))
            .setOAuthRequestTokenURL((String) props.get("twitterRequestTokenURL"))
            .setOAuthAuthorizationURL((String) props.get("twitterAuthorizeURL"))
            .setOAuthAccessTokenURL((String) props.get("twitterAccessTokenURL"));
    TwitterFactory tf = new TwitterFactory(cb.build());
    Twitter twitter = tf.getInstance();/* www.j  a  va2 s  .  co  m*/
    request.getSession().setAttribute("twitter", twitter);
    try {
        StringBuffer callbackURL = request.getRequestURL();
        System.out.println("TwitterLoginServlet:callbackURL:" + callbackURL);
        int index = callbackURL.lastIndexOf("/");
        callbackURL.replace(index, callbackURL.length(), "").append("/TwitterCallback");

        RequestToken requestToken = twitter.getOAuthRequestToken(callbackURL.toString());
        request.getSession().setAttribute("requestToken", requestToken);
        System.out.println("requestToken.getAuthenticationURL():" + requestToken.getAuthenticationURL());
        response.sendRedirect(requestToken.getAuthenticationURL());

    } catch (TwitterException e) {
        throw new ServletException(e);
    }

}