List of usage examples for twitter4j.conf ConfigurationBuilder setApplicationOnlyAuthEnabled
public ConfigurationBuilder setApplicationOnlyAuthEnabled(boolean applicationOnlyAuthEnabled)
From source file:Beans.Crawler.java
/** * Retrieve the "bearer" token from Twitter in order to make application-authenticated calls. * * This is the first step in doing application authentication, as described in Twitter's documentation at * https://dev.twitter.com/docs/auth/application-only-auth * * Note that if there's an error in this process, we just print a message and quit. That's a pretty * dramatic side effect, and a better implementation would pass an error back up the line... * * @return The oAuth2 bearer token/* w w w . j a v a 2 s . co m*/ */ public static OAuth2Token getOAuth2Token() { OAuth2Token token = null; ConfigurationBuilder cb; cb = new ConfigurationBuilder(); cb.setApplicationOnlyAuthEnabled(true); cb.setOAuthConsumerKey(CONSUMER_KEY).setOAuthConsumerSecret(CONSUMER_SECRET); try { token = new TwitterFactory(cb.build()).getInstance().getOAuth2Token(); } catch (Exception e) { System.out.println("Could not get OAuth2 token"); e.printStackTrace(); System.exit(0); } return token; }
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 *///ww w . ja v a2 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:br.com.controller.TweetController.java
public static OAuth2Token getOAuth2Token() { OAuth2Token token = null;/*from ww w .ja v a 2 s . c o m*/ ConfigurationBuilder cb; cb = new ConfigurationBuilder(); cb.setApplicationOnlyAuthEnabled(true); cb.setOAuthConsumerKey(CONSUMER_KEY).setOAuthConsumerSecret(CONSUMER_SECRET); try { token = new TwitterFactory(cb.build()).getInstance().getOAuth2Token(); } catch (Exception e) { System.out.println("Could not get OAuth2 token"); e.printStackTrace(); System.exit(0); } return token; }
From source file:br.com.controller.TweetController.java
public static Twitter getTwitter() { OAuth2Token token;//from w w w. j a v a 2s . c om 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:com.adobe.acs.commons.twitter.impl.TwitterAdapterFactory.java
License:Apache License
private Configuration buildConfiguration() { final ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setUseSSL(true);/*w w w. j a v a 2 s .co m*/ builder.setApplicationOnlyAuthEnabled(true); return builder.build(); }
From source file:com.alainesp.fan.sanderson.SummaryFragment.java
License:Open Source License
protected int doWork() { int state = DownloadParseSaveTask.STATE_SUCCESS; try {//from w ww . j a v a 2 s .c o m List<twitter4j.Status> tweets; // Twitter client configuration ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(TwitterAPISecrets.CONSUMER_KEY) .setOAuthConsumerSecret(TwitterAPISecrets.CONSUMER_SECRET); // TODO: Use guest authentication instead of application builder.setApplicationOnlyAuthEnabled(true).setDebugEnabled(false).setGZIPEnabled(true); Twitter twitter = new TwitterFactory(builder.build()).getInstance(); twitter.getOAuth2Token(); // Get the tweets long lastTweetID = DB.Tweet.getLastTweetID(); if (lastTweetID <= 0) tweets = twitter.getUserTimeline("BrandSanderson"); else tweets = twitter.getUserTimeline("BrandSanderson", new Paging(lastTweetID)); if (tweets != null) { long brandonID = 28187205; Hashtable<Long, DB.Tweet> findTweet = new Hashtable<>(tweets.size() * 16, 0.25f); List<DB.Tweet> dbTweets = new ArrayList<>(tweets.size()); for (twitter4j.Status tweet : tweets) { // Create the tweet if (tweet.isRetweet()) tweet = tweet.getRetweetedStatus(); long tweetID = tweet.getId(); // TODO: Include the tweets in the DB if (findTweet.get(tweetID) == null)// This eliminate tweets already in the replies tree { DB.Tweet dbTweet = new DB.Tweet(tweetID, getTweetText(tweet), tweet.getCreatedAt(), false, tweet.getUser().getName(), tweet.getUser().getBiggerProfileImageURLHttps()); InternetHelper.getRemoteFile(tweet.getUser().getBiggerProfileImageURLHttps()); dbTweets.add(dbTweet); findTweet.put(tweetID, dbTweet); // Traverse the tree of the replies tweets twitter4j.Status treeTweet = tweet; while (treeTweet != null && treeTweet.getInReplyToStatusId() >= 0) { try { long id = treeTweet.getInReplyToStatusId(); long userID = treeTweet.getUser().getId(); treeTweet = null; if (findTweet.get(id) == null || brandonID == userID) treeTweet = twitter.showStatus(id); else// Remove duplicates. Not sure why they appear, but the difference of the text is a dot at the end. dbTweets.remove(dbTweets.size() - 1); } catch (Exception ignore) { } if (treeTweet != null) { findTweet.put(treeTweet.getId(), dbTweet); StringBuilder replyBuilder = new StringBuilder(); replyBuilder.append("<blockquote>"); // Profile image replyBuilder.append("<img src=\""); InternetHelper.getRemoteFile(treeTweet.getUser().getBiggerProfileImageURLHttps()); replyBuilder.append(treeTweet.getUser().getBiggerProfileImageURLHttps()); replyBuilder.append("\"/> <b>"); // Username - date replyBuilder.append(treeTweet.getUser().getName()); replyBuilder.append("</b> @"); replyBuilder.append(treeTweet.getUser().getScreenName()); replyBuilder.append(" - "); replyBuilder .append(TwitterFragment.showDateFormat.format(treeTweet.getCreatedAt())); // Tweet text replyBuilder.append("<br/>"); replyBuilder.append(getTweetText(treeTweet)); // Remaining replyBuilder.append(dbTweet.htmlReply); replyBuilder.append("</blockquote>"); dbTweet.htmlReply = replyBuilder.toString(); } } } } DB.Tweet.updateTwitter(dbTweets); } } catch (Exception e) { Logger.reportError(e.toString()); state = DownloadParseSaveTask.STATE_ERROR_PARSING; } return state; }
From source file:com.data.dataanalytics.twitter.TwitterFeed.java
private static OAuth2Token getOAuth2Token() { OAuth2Token token = null;// w w w.j ava 2s . c o m ConfigurationBuilder cb; cb = new ConfigurationBuilder(); cb.setApplicationOnlyAuthEnabled(true); cb.setOAuthConsumerKey(CONSUMER_KEY).setOAuthConsumerSecret(CONSUMER_SECRET); try { token = new TwitterFactory(cb.build()).getInstance().getOAuth2Token(); } catch (Exception e) { System.out.println("Could not get OAuth2 token"); e.printStackTrace(); System.exit(0); } return token; }
From source file:com.data.dataanalytics.twitter.TwitterFeed.java
/** * Get a fully application-authenticated Twitter object useful for making subsequent calls. * *//*w w w.j a va2 s . c om*/ protected static twitter4j.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()); // Create the Twitter object return new TwitterFactory(cb.build()).getInstance(); }
From source file:ontoSentiment.Util.java
public static OAuth2Token getOAuth2Token() { OAuth2Token token = null;/*from www. ja v a 2 s. co m*/ ConfigurationBuilder cb; cb = new ConfigurationBuilder(); cb.setApplicationOnlyAuthEnabled(true); cb.setOAuthConsumerKey(CONSUMER_KEY).setOAuthConsumerSecret(CONSUMER_SECRET); try { token = new TwitterFactory(cb.build()).getInstance().getOAuth2Token(); } catch (Exception e) { System.out.println("Could not get OAuth2 token"); e.printStackTrace(); System.exit(0); } return token; }
From source file:ontoSentiment.Util.java
public static Twitter getTwitter() { OAuth2Token token;//from w ww. j ava 2s.co 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(); }