List of usage examples for twitter4j.conf ConfigurationBuilder setOAuthConsumerSecret
public ConfigurationBuilder setOAuthConsumerSecret(String oAuthConsumerSecret)
From source file:adapter.TwitterKeywordsAdapter.java
License:Apache License
public void connectAndRead() throws Exception { ConfigurationBuilder cb = new ConfigurationBuilder(); Properties twitterProperties = new Properties(); File twitter4jPropsFile = new File("../twitter4j.properties"); if (!twitter4jPropsFile.exists()) { logger.error("Cannot find twitter4j.properties file in this location :[{}]", twitter4jPropsFile.getAbsolutePath()); return;//from w w w . j a v a2s .c om } twitterProperties.load(new FileInputStream(twitter4jPropsFile)); cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey(twitterProperties.getProperty("oauth.consumerKey")); cb.setOAuthConsumerSecret(twitterProperties.getProperty("oauth.consumerSecret")); cb.setOAuthAccessToken(twitterProperties.getProperty("oauth.accessToken")); cb.setOAuthAccessTokenSecret(twitterProperties.getProperty("oauth.accessTokenSecret")); cb.setDebugEnabled(false); cb.setPrettyDebugEnabled(false); cb.setIncludeMyRetweetEnabled(false); TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); StatusListener statusListener = new StatusListener() { @Override public void onException(Exception ex) { } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { } @Override public void onStatus(Status status) { messageQueue.add(status); } @Override public void onScrubGeo(long userId, long upToStatusId) { } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { } @Override public void onStallWarning(StallWarning arg0) { } }; FilterQuery fq = new FilterQuery(); //System.out.println(Arrays.toString(configuration.getTrack())); //Elige todos los tweets que posean esas palabras claves fq.track(new String[] { "palabra1,palabra2,palabra3" }); //fq.track(keywords); twitterStream.addListener(statusListener); twitterStream.filter(fq); }
From source file:adapter.TwitterLanguageAdapter.java
License:Apache License
public void connectAndRead() throws Exception { ConfigurationBuilder cb = new ConfigurationBuilder(); Properties twitterProperties = new Properties(); File twitter4jPropsFile = new File("../twitter4j.properties"); if (!twitter4jPropsFile.exists()) { logger.error("Cannot find twitter4j.properties file in this location :[{}]", twitter4jPropsFile.getAbsolutePath()); return;/*from w w w .j av a2 s .c o m*/ } twitterProperties.load(new FileInputStream(twitter4jPropsFile)); cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey(twitterProperties.getProperty("oauth.consumerKey")); cb.setOAuthConsumerSecret(twitterProperties.getProperty("oauth.consumerSecret")); cb.setOAuthAccessToken(twitterProperties.getProperty("oauth.accessToken")); cb.setOAuthAccessTokenSecret(twitterProperties.getProperty("oauth.accessTokenSecret")); cb.setDebugEnabled(false); cb.setPrettyDebugEnabled(false); cb.setIncludeMyRetweetEnabled(false); TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); StatusListener statusListener = new StatusListener() { @Override public void onException(Exception ex) { } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { } @Override public void onStatus(Status status) { messageQueue.add(status); } @Override public void onScrubGeo(long userId, long upToStatusId) { } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { } @Override public void onStallWarning(StallWarning arg0) { } }; //Filter language and track FilterQuery tweetFilterQuery = new FilterQuery(); tweetFilterQuery.track(new String[] { "palabra1,palabra2,palabra3" }); tweetFilterQuery.language(new String[] { "es" }); //TwitterStream twitterStream.addListener(statusListener); twitterStream.filter(tweetFilterQuery); }
From source file:adapter.TwitterLocationAdapter.java
License:Apache License
public void connectAndRead() throws Exception { ConfigurationBuilder cb = new ConfigurationBuilder(); Properties twitterProperties = new Properties(); File twitter4jPropsFile = new File("../twitter4j.properties"); if (!twitter4jPropsFile.exists()) { logger.error("Cannot find twitter4j.properties file in this location :[{}]", twitter4jPropsFile.getAbsolutePath()); return;//www . ja v a2 s.c o m } twitterProperties.load(new FileInputStream(twitter4jPropsFile)); cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey(twitterProperties.getProperty("oauth.consumerKey")); cb.setOAuthConsumerSecret(twitterProperties.getProperty("oauth.consumerSecret")); cb.setOAuthAccessToken(twitterProperties.getProperty("oauth.accessToken")); cb.setOAuthAccessTokenSecret(twitterProperties.getProperty("oauth.accessTokenSecret")); cb.setDebugEnabled(false); cb.setPrettyDebugEnabled(false); cb.setIncludeMyRetweetEnabled(false); TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); StatusListener statusListener = new StatusListener() { @Override public void onException(Exception ex) { } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { } @Override public void onStatus(Status status) { messageQueue.add(status); } @Override public void onScrubGeo(long userId, long upToStatusId) { } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { } @Override public void onStallWarning(StallWarning arg0) { } }; FilterQuery fq = new FilterQuery(); // Posiciones geogrficas, esas dos coordenadas son el vrtice superior izquierda e inferior derecho // de un rectangulo, de tal manera de analizar solo una parte geografica double position[][] = { { 0.0, 0.0 }, { 0.0, 0.0 } }; fq.locations(position); twitterStream.addListener(statusListener); twitterStream.filter(fq); }
From source file:Beans.Crawler.java
/** * Get a fully application-authenticated Twitter object useful for making subsequent calls. * * @return Twitter4J Twitter object that's ready for API calls *//*from w ww.ja v a 2 s .com*/ public static Twitter getTwitter() { OAuth2Token token; // First step, get a "bearer" token that can be used for our requests token = getOAuth2Token(); // Now, configure our new Twitter object to use application authentication and provide it with // our CONSUMER key and secret and the bearer token we got back from Twitter ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setApplicationOnlyAuthEnabled(true); cb.setOAuthConsumerKey(CONSUMER_KEY); cb.setOAuthConsumerSecret(CONSUMER_SECRET); cb.setOAuth2TokenType(token.getTokenType()); cb.setOAuth2AccessToken(token.getAccessToken()); // And create the Twitter object! return new TwitterFactory(cb.build()).getInstance(); }
From source file:benche.me.TwitterParser.Main.java
License:Open Source License
/** * Configure twitter API connection for tweet streaming * @return TwitterStream instance//from ww w .ja v a2s. c o m */ private static TwitterStream configureStream() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey(Constants.CONSUMER_KEY_KEY); cb.setOAuthConsumerSecret(Constants.CONSUMER_SECRET_KEY); cb.setOAuthAccessToken(Constants.ACCESS_TOKEN_KEY); cb.setOAuthAccessTokenSecret(Constants.ACCESS_TOKEN_SECRET_KEY); cb.setJSONStoreEnabled(true); cb.setIncludeEntitiesEnabled(true); return new TwitterStreamFactory(cb.build()).getInstance(); }
From source file:br.com.controller.TweetController.java
public static Twitter getTwitter() { OAuth2Token token;/*w w w. ja v a 2s. c o m*/ token = getOAuth2Token(); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setApplicationOnlyAuthEnabled(true); cb.setOAuthConsumerKey(CONSUMER_KEY); cb.setOAuthConsumerSecret(CONSUMER_SECRET); cb.setOAuth2TokenType(token.getTokenType()); cb.setOAuth2AccessToken(token.getAccessToken()); return new TwitterFactory(cb.build()).getInstance(); }
From source file:co.uk.socialticker.ticker.TickerActivity.java
License:Open Source License
/** * Function to login twitter/*from w w w. ja v a 2 s.c o m*/ * */ private void loginToTwitter() { // Check if already logged in if (!isTwitterLoggedInAlready()) { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY); builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET); Configuration configuration = builder.build(); TwitterFactory factory = new TwitterFactory(configuration); twitter = factory.getInstance(); try { requestToken = twitter.getOAuthRequestToken(TWITTER_CALLBACK_URL); this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(requestToken.getAuthenticationURL()))); } catch (TwitterException e) { e.printStackTrace(); } } else { // user already logged into twitter Toast.makeText(getApplicationContext(), "Already Logged into twitter", Toast.LENGTH_LONG).show(); } }
From source file:co.uk.socialticker.ticker.TickerActivity.java
License:Open Source License
/** * Test code to try and retrieve some data from twitter in a search! * @throws TwitterException //from w ww . j av a 2s.c o m * */ public JSONArray doSearch(View v) throws TwitterException { if (mApiClient != null || debugOn) { // The factory instance is re-useable and thread safe. //get the hashtag - check to make sure if returned value is set to something with a length JSONArray jsA = new JSONArray(); String qHash = p.getString(KEY_CAST_HASHTAG, ""); Log.d(TAG, "Hash to search: " + qHash); if (qHash.length() == 0) { Toast.makeText(this, "The hashtag looks like it is not setup. May want to fix that", Toast.LENGTH_LONG).show(); } else { try { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY); builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET); // Access Token String access_token = mSharedPreferences.getString(PREF_KEY_OAUTH_TOKEN, ""); // Access Token Secret String access_token_secret = mSharedPreferences.getString(PREF_KEY_OAUTH_SECRET, ""); AccessToken accessToken = new AccessToken(access_token, access_token_secret); Twitter twitter = new TwitterFactory(builder.build()).getInstance(accessToken); //Query query = new Query("#MOTD2014"); Query query = new Query(qHash); query.count(TWEET_COUNT); QueryResult result = twitter.search(query); for (twitter4j.Status status : result.getTweets()) { MediaEntity[] me = status.getMediaEntities(); String meUrl = ""; if (me.length > 0) { Log.d(TAG, "me[0] : " + me[0].getMediaURL()); //meUrl = me[0].getDisplayURL(); //sjort URl = useless. meUrl = me[0].getMediaURL(); } JSONObject jso = tweetJSON(status.getUser().getScreenName(), status.getUser().getName() // , status.getUser().getOriginalProfileImageURL() //Whatever the size was it was uploaded in // , status.getUser().getProfileImageURL() // 48x48 , status.getUser().getBiggerProfileImageURL() // 73x73 , status.getText(), status.getCreatedAt().toString(), status.getFavoriteCount(), status.getRetweetCount(), meUrl); jsA.put(jso); } } catch (TwitterException e) { // Error in updating status Log.d("Twitter Search Error", e.getMessage()); Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); } } ; return jsA; } else { Toast.makeText(this, "You do not seem to be connected to a cast device...", Toast.LENGTH_LONG).show(); return null; } }
From source file:com.ak.android.akplaza.common.sns.twitter.TwitterController.java
License:Open Source License
public static void write(String content, Activity at) { // Log.d(TAG, "content : " + content); String path = Environment.getExternalStorageDirectory().getAbsolutePath(); String fileName = "example.jpg"; InputStream is = null;// w w w . j a v a 2 s . c o m try { if (new File(path + File.separator + fileName).exists()) is = new FileInputStream(path + File.separator + fileName); else is = null; ConfigurationBuilder cb = new ConfigurationBuilder(); String oAuthAccessToken = acToken.getToken(); String oAuthAccessTokenSecret = tacs; String oAuthConsumerKey = C.TWITTER_CONSUMER_KEY; String oAuthConsumerSecret = C.TWITTER_CONSUMER_SECRET; cb.setOAuthAccessToken(oAuthAccessToken); cb.setOAuthAccessTokenSecret(oAuthAccessTokenSecret); cb.setOAuthConsumerKey(oAuthConsumerKey); cb.setOAuthConsumerSecret(oAuthConsumerSecret); Configuration config = cb.build(); OAuthAuthorization auth = new OAuthAuthorization(config); TwitterFactory tFactory = new TwitterFactory(config); Twitter twitter = tFactory.getInstance(); // ImageUploadFactory iFactory = new ImageUploadFactory(getConfiguration(C.TWITPIC_API_KEY)); // ImageUpload upload = iFactory.getInstance(MediaProvider.TWITPIC, auth); if (is != null) { // String strResult = upload.upload("example.jpg", is, mEtContent.getText().toString()); // twitter.updateStatus(mEtContent.getText().toString() + " " + strResult); } else twitter.updateStatus(content); new AlertDialog.Builder(at).setMessage(" ? ? ?.") .setPositiveButton("?", null).show(); } catch (Exception e) { e.printStackTrace(); new AlertDialog.Builder(at).setMessage("? ? ") .setPositiveButton("?", null).show(); } finally { try { is.close(); } catch (Exception e) { } } }
From source file:com.arihant15.ActionServlet.java
@RequestMapping("/login.arihant15") public void doLogin(HttpServletRequest req, HttpServletResponse res) { try {/*from w w w .j a v a 2 s. c o m*/ ConfigurationBuilder configuration = new ConfigurationBuilder(); configuration.setOAuthConsumerKey(ConsumerKey); configuration.setOAuthConsumerSecret(ConsumerSecret); TwitterFactory twitterfactory = new TwitterFactory(configuration.build()); Twitter twitter = twitterfactory.getInstance(); req.getSession().setAttribute("t", twitter); RequestToken requestToken = twitter.getOAuthRequestToken(); req.getSession().setAttribute("rToken", requestToken); res.sendRedirect(requestToken.getAuthenticationURL()); } catch (Exception e) { e.printStackTrace(); } }