List of usage examples for twitter4j.conf ConfigurationBuilder ConfigurationBuilder
ConfigurationBuilder
From source file:org.rtsa.storm.TwitterSpout.java
License:Apache License
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) { queue = new LinkedBlockingQueue<Status>(1000); _collector = collector;// w w w . j a v a 2 s .co m StatusListener listener = new StatusListener() { public void onStatus(Status status) { if (status.getText().length() != 0 && status.getLang().equals("en")) { queue.offer(status); } } public void onDeletionNotice(StatusDeletionNotice sdn) { } public void onTrackLimitationNotice(int i) { } public void onScrubGeo(long l, long l1) { } public void onException(Exception ex) { } public void onStallWarning(StallWarning arg0) { // TODO Auto-generated method stub } }; TwitterStream twitterStream = new TwitterStreamFactory( new ConfigurationBuilder().setJSONStoreEnabled(true).build()).getInstance(); twitterStream.addListener(listener); twitterStream.setOAuthConsumer(consumerKey, consumerSecret); AccessToken token = new AccessToken(accessToken, accessTokenSecret); twitterStream.setOAuthAccessToken(token); if (keyWords.length == 0) { twitterStream.sample(); } else { FilterQuery query = new FilterQuery().track(keyWords); twitterStream.filter(query); } }
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]"); }// w w w.j a va 2 s . 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);//from w ww . ja v a 2 s . c o m 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; 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();/*from w w w . j a va 2 s . com*/ 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); } }
From source file:org.socialnetlib.android.TwitterApi.java
License:Apache License
Twitter getAndConfigureApiInstance() { if (mCurrentOAuthToken == null || mCurrentOAuthSecret == null) { mSocNetApi = null;/*from w ww . j a v a 2 s . c o m*/ mOAuth = null; } else if (mSocNetApi == null) { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setDebugEnabled(true).setOAuthConsumerKey(mAppConsumerKey) .setOAuthConsumerSecret(mAppConsumerSecret).setOAuthAccessToken(mCurrentOAuthToken) .setOAuthAccessTokenSecret(mCurrentOAuthSecret).setMediaProvider("TWITTER") // .setJSONStoreEnabled(true) .setIncludeEntitiesEnabled(true); Configuration configuration = configurationBuilder.build(); mSocNetApi = new TwitterFactory(configuration).getInstance(); // mOAuth = new // TwitterFactory(configuration).getOAuthAuthorization(); } return mSocNetApi; }
From source file:org.sociotech.communitymashup.source.twitter.TwitterSourceService.java
License:Open Source License
/** * Establishes a connection with twitter based on the user information given * in the configuration./* www . j av a 2 s .co m*/ * * @return True if it is possible to use the user information for the * connection, false otherwise. */ private boolean establishConnection() { // get property values from configuration String consumerKey = source.getPropertyValue(TwitterProperties.CONSUMER_KEY_PROPERTY); String consumerSecret = source.getPropertyValue(TwitterProperties.CONSUMER_SECRET_PROPERTY); String accessTokenValue = source.getPropertyValue(TwitterProperties.ACCESS_TOKEN_PROPERTY); String accessTokenSecret = source.getPropertyValue(TwitterProperties.ACCESS_TOKEN_SECRET_PROPERTY); // check properties if (consumerKey == null || consumerKey.isEmpty()) { log("A valid consumer key is needed in the configuration specified by " + TwitterProperties.CONSUMER_KEY_PROPERTY, LogService.LOG_WARNING); return false; } else if (consumerSecret == null || consumerSecret.isEmpty()) { log("A valid consumer secret is needed in the configuration specified by " + TwitterProperties.CONSUMER_SECRET_PROPERTY, LogService.LOG_WARNING); return false; } else if (accessTokenValue == null || accessTokenValue.isEmpty()) { log("A valid access token is needed in the configuration specified by " + TwitterProperties.ACCESS_TOKEN_PROPERTY, LogService.LOG_WARNING); return false; } else if (accessTokenSecret == null || accessTokenSecret.isEmpty()) { log("A valid token secret is needed in the configuration specified by " + TwitterProperties.ACCESS_TOKEN_SECRET_PROPERTY, LogService.LOG_WARNING); return false; } // get access with the provided credencials // TODO disable debug ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret) .setOAuthAccessToken(accessTokenValue).setOAuthAccessTokenSecret(accessTokenSecret); TwitterFactory tf = new TwitterFactory(cb.build()); twitterAPI = tf.getInstance(); if (twitterAPI == null) { log("Could not create a connection to the twitter api!", LogService.LOG_ERROR); } return true; }
From source file:org.streaming.spring.StreamingUtils.java
License:Apache License
public static Configuration getTwitterConfig() { Configuration config = new ConfigurationBuilder().setOAuthConsumerKey(_consumerkey) .setOAuthConsumerSecret(_consumerSecret).setOAuthAccessToken(_accessToken) .setOAuthAccessTokenSecret(_accessTokenSecret).build(); return config; }
From source file:org.structr.web.auth.TwitterAuthClient.java
License:Open Source License
@Override protected void init(final String authorizationLocation, final String tokenLocation, final String clientId, final String clientSecret, final String redirectUri, final Class tokenResponseClass) { super.init(authorizationLocation, tokenLocation, clientId, clientSecret, redirectUri, tokenResponseClass); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthAuthorizationURL(authorizationLocation); cb.setOAuthAccessTokenURL(tokenLocation); Configuration conf = cb.build(); TwitterFactory tf = new TwitterFactory(conf); twitter = tf.getInstance();//from w ww. j a v a 2 s.c o m twitter.setOAuthConsumer(clientId, clientSecret); }
From source file:org.sush.twitterstream.MyTwitterStream.java
License:Apache License
public void init() throws IOException { configurationBuilder = new ConfigurationBuilder(); String configDIr = System.getenv("SUSH_JAVA_CONFIG"); File file = new File("E:\\java_config\\twitter4j.properties"); Properties properties = new Properties(); if (file.exists()) { InputStream fileInputStream = new FileInputStream(file); properties.load(fileInputStream); } else {//from w ww. j a va 2s . co m System.out.println("Property file not found... Program Exiting"); System.exit(-1); } String oAuthConsumerKey = properties.getProperty("oauth.consumerSecret", ""); String oAuthConsumerSecret = properties.getProperty("oauth.consumerKey", ""); configurationBuilder.setOAuthConsumerKey(oAuthConsumerKey); configurationBuilder.setOAuthConsumerSecret(oAuthConsumerSecret); twitterException = null; twitterStream = new TwitterStreamFactory(configurationBuilder.build()).getInstance(); statusListener = new MyTwitterStatusListener(this); connectionListener = new MyTwitterConnectionLifeCycleListener(this); twitterStream.addListener(statusListener); twitterStream.addConnectionLifeCycleListener(connectionListener); }
From source file:org.talend.spark.operation.TwitterLoad.java
License:Open Source License
public static JavaDStream<List<Object>> twitterStream(JavaStreamingContext ctx, String username, String password, String accessToken, String secretToken, String[] filters, List<TwitterParameter> twitterParameters) { twitter4j.conf.ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthAccessToken(accessToken); builder.setOAuthAccessTokenSecret(secretToken); builder.setOAuthConsumerKey(username); builder.setOAuthConsumerSecret(password); JavaDStream<Status> inputDStream = null; if (filters.length > 0) { if (filters.length == 1 && filters[0].equals("")) inputDStream = TwitterUtils.createStream(ctx, new OAuthAuthorization(builder.build())); else/*w w w . j av a 2 s . c om*/ inputDStream = TwitterUtils.createStream(ctx, new OAuthAuthorization(builder.build()), filters); return inputDStream.map(new LoadTwitterFunction(twitterParameters)); } return null; }