List of usage examples for twitter4j TwitterFactory TwitterFactory
public TwitterFactory(String configTreePath)
From source file:com.daiv.android.twitter.utils.Utils.java
License:Apache License
public static Twitter getTwitter(Context context) { AppSettings settings = AppSettings.getInstance(context); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(AppSettings.TWITTER_CONSUMER_KEY) .setOAuthConsumerSecret(AppSettings.TWITTER_CONSUMER_SECRET) .setOAuthAccessToken(settings.authenticationToken) .setOAuthAccessTokenSecret(settings.authenticationTokenSecret); TwitterFactory tf = new TwitterFactory(cb.build()); return tf.getInstance(); }
From source file:com.daiv.android.twitter.utils.Utils.java
License:Apache License
public static Twitter getSecondTwitter(Context context) { AppSettings settings = AppSettings.getInstance(context); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(AppSettings.TWITTER_CONSUMER_KEY) .setOAuthConsumerSecret(AppSettings.TWITTER_CONSUMER_SECRET) .setOAuthAccessToken(settings.secondAuthToken) .setOAuthAccessTokenSecret(settings.secondAuthTokenSecret); TwitterFactory tf = new TwitterFactory(cb.build()); return tf.getInstance(); }
From source file:com.data.dataanalytics.twitter.TwitterFeed.java
private static OAuth2Token getOAuth2Token() { OAuth2Token token = null;//from ww w. j av a 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. * *///from www .ja v a 2 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:com.dhamacher.sentimentanalysis4tweets.twitterapi.TweetOperator.java
License:Apache License
public TweetOperator(int mode) { try {/*from w w w .j a v a 2s . co m*/ this.mode = mode; db = Operator.getInstance(); } catch (Exception ex) { ex.printStackTrace(); } if (mode == 3 || mode == 2) { TwitterFactory twitterFactory = new TwitterFactory(buildConfig()); twitter = twitterFactory.getInstance(); } }
From source file:com.dvd.codechallenge.Challengue.java
public static Tweets getTweets(String user) throws TwitterException { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("sMYxrCslzDDHGhFn5MSvPMWhw") .setOAuthConsumerSecret("ip8E4OoTGNQetDHz8oTereIsXAnO2cGlgs7Dd2S4lXti4weHAt") .setOAuthAccessToken("451175684-DBydPtZsitmr6EHPVansnVygQXRALCCKnKUqUa4W") .setOAuthAccessTokenSecret("prPHOfZj3IMFrW7ToFbKWJkRjWHM2qlpUdSecEZyuhLvd"); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance();//from www . java 2 s . c o m List<Status> statuses = twitter.getUserTimeline(user); // System.out.println("Tweets recuperados"); // statuses.forEach(x -> System.out.println(x.getUser().getName() // + "-> " + x.getUser().getScreenName() + ":::" // + x.getText())); Tweets ts = new Tweets(); statuses.forEach(x -> ts.addTweet(x.getText())); return ts; }
From source file:com.dwdesign.tweetings.util.Utils.java
License:Open Source License
public static Twitter getTwitterInstance(final Context context, final long account_id, final boolean include_entities, final boolean include_rts, final boolean use_httpclient) { if (context == null) return null; final SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); final boolean enable_gzip_compressing = preferences != null ? preferences.getBoolean(PREFERENCE_KEY_GZIP_COMPRESSING, true) : true;/* www . ja v a2s . co m*/ final boolean ignore_ssl_error = preferences != null ? preferences.getBoolean(PREFERENCE_KEY_IGNORE_SSL_ERROR, false) : false; final boolean enable_proxy = preferences != null ? preferences.getBoolean(PREFERENCE_KEY_ENABLE_PROXY, false) : false; final String consumer_key = preferences != null ? preferences.getString(PREFERENCE_KEY_CONSUMER_KEY, CONSUMER_KEY) : CONSUMER_KEY; final String consumer_secret = preferences != null ? preferences.getString(PREFERENCE_KEY_CONSUMER_SECRET, CONSUMER_SECRET) : CONSUMER_SECRET; Twitter twitter = null; final StringBuilder where = new StringBuilder(); where.append(Accounts.USER_ID + "=" + account_id); final Cursor cur = context.getContentResolver().query(Accounts.CONTENT_URI, Accounts.COLUMNS, where.toString(), null, null); if (cur != null) { if (cur.getCount() == 1) { cur.moveToFirst(); final ConfigurationBuilder cb = new ConfigurationBuilder(); setUserAgent(context, cb); if (use_httpclient) { cb.setHttpClientImplementation(HttpClientImpl.class); } cb.setGZIPEnabled(enable_gzip_compressing); if (enable_proxy) { final String proxy_host = preferences.getString(PREFERENCE_KEY_PROXY_HOST, null); final int proxy_port = parseInt(preferences.getString(PREFERENCE_KEY_PROXY_PORT, "-1")); if (!isNullOrEmpty(proxy_host) && proxy_port > 0) { cb.setHttpProxyHost(proxy_host); cb.setHttpProxyPort(proxy_port); } } final String rest_base_url = cur.getString(cur.getColumnIndexOrThrow(Accounts.REST_BASE_URL)); final String signing_rest_base_url = cur .getString(cur.getColumnIndexOrThrow(Accounts.SIGNING_REST_BASE_URL)); final String search_base_url = cur.getString(cur.getColumnIndexOrThrow(Accounts.SEARCH_BASE_URL)); final String upload_base_url = cur.getString(cur.getColumnIndexOrThrow(Accounts.UPLOAD_BASE_URL)); final String oauth_base_url = cur.getString(cur.getColumnIndexOrThrow(Accounts.OAUTH_BASE_URL)); final String signing_oauth_base_url = cur .getString(cur.getColumnIndexOrThrow(Accounts.SIGNING_OAUTH_BASE_URL)); //if (!isNullOrEmpty(rest_base_url)) { cb.setRestBaseURL(DEFAULT_REST_BASE_URL); //} //if (!isNullOrEmpty(search_base_url)) { cb.setSearchBaseURL(DEFAULT_SEARCH_BASE_URL); //} cb.setIncludeEntitiesEnabled(include_entities); cb.setIncludeRTsEnabled(include_rts); switch (cur.getInt(cur.getColumnIndexOrThrow(Accounts.AUTH_TYPE))) { case Accounts.AUTH_TYPE_OAUTH: case Accounts.AUTH_TYPE_XAUTH: if (isNullOrEmpty(consumer_key) || isNullOrEmpty(consumer_secret)) { cb.setOAuthConsumerKey(CONSUMER_KEY); cb.setOAuthConsumerSecret(CONSUMER_SECRET); } else { cb.setOAuthConsumerKey(consumer_key); cb.setOAuthConsumerSecret(consumer_secret); } twitter = new TwitterFactory(cb.build()).getInstance( new AccessToken(cur.getString(cur.getColumnIndexOrThrow(Accounts.OAUTH_TOKEN)), cur.getString(cur.getColumnIndexOrThrow(Accounts.TOKEN_SECRET)))); break; case Accounts.AUTH_TYPE_BASIC: twitter = new TwitterFactory(cb.build()).getInstance( new BasicAuthorization(cur.getString(cur.getColumnIndexOrThrow(Accounts.USERNAME)), cur.getString(cur.getColumnIndexOrThrow(Accounts.BASIC_AUTH_PASSWORD)))); break; default: } } cur.close(); } return twitter; }
From source file:com.example.leonid.twitterreader.Twitter.TwitterGetTweets.java
License:Apache License
@Override protected List<CreateTweet> doInBackground(String... params) { mTweetsInfo = new ArrayList<>(); List<String> texts = new ArrayList<>(); List<String> titles = new ArrayList<>(); List<String> images = new ArrayList<>(); List<String> date = new ArrayList<>(); if (!isCancelled()) { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(CONSUMER_KEY).setOAuthConsumerSecret(CONSUMER_SECRET) .setOAuthAccessToken(ACCESS_KEY).setOAuthAccessTokenSecret(ACCESS_SECRET); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); //query search result Query query = new Query(params[0]); //how much tweets need to be displayed(max 200) query.count(200);//w w w. j a va 2s . c o m try { mResult = twitter.search(query); for (twitter4j.Status status : mResult.getTweets()) { if (!isCancelled()) { texts.add(status.getText()); titles.add(status.getUser().getName()); images.add(status.getUser().getBiggerProfileImageURL()); String cleanDate = status.getCreatedAt().toString(); date.add(cleanDate.substring(0, cleanDate.length() - 15) + " " + cleanDate.substring(cleanDate.length() - 4)); } } } catch (TwitterException e) { Log.e("exeption", e.toString()); } //loop teuth results and create array list for list view for (int i = 0; i < texts.size(); i++) { mTweetsInfo.add(new CreateTweet(titles.get(i), images.get(i), texts.get(i), date.get(i))); } } return mTweetsInfo; }
From source file:com.freedomotic.plugins.devices.twitter.gateways.TwitterGateway.java
License:Open Source License
public static synchronized Twitter getInstance(Config configuration) { if (twitter == null) { ConfigurationBuilder cb = new ConfigurationBuilder(); //TODO: create a default twitter account for freedom project. If the user do not customize the oauth parameters in //config file we can use by default the parameters of the freedom twitter account (the second argument in getStringProperty). cb.setDebugEnabled(true).setOAuthConsumerKey(configuration.getStringProperty("OAuthConsumerKey", null)) //"TLGtvoeABqf2tEG4itTUaw") .setOAuthConsumerSecret(configuration.getStringProperty("OAuthConsumerSecret", null)) //"nUJPxYR1qJmhX9SnWTBT0MzO7dIqUtNyVPfhg10wf0") .setOAuthAccessToken(configuration.getStringProperty("OAuthAccessToken", null))//"312792183-adnYVIv06spR4qsI3eKVv53CfrYHl3KqgtJtYm10") .setOAuthAccessTokenSecret(configuration.getStringProperty("OAuthAccessTokenSecret", null));//("Br2O2wtZ2dsLMDN21qKdlCLsOuqXW8h3z3uButRk"); TwitterFactory tf = new TwitterFactory(cb.build()); twitter = tf.getInstance();/*from w w w. j a va 2s.co m*/ } return twitter; }
From source file:com.fsatir.twitter.TwitterManagedBean.java
public Twitter bringMyTwitterInstance() throws TwitterException { String consumerKey = TwitterInfos.CONSUMER_KEY.getCredentialValue(); String consumerSecret = TwitterInfos.CONSUMER_SECRET.getCredentialValue(); String oAuthToken = TwitterInfos.OAUTH_TOKEN.getCredentialValue(); String oAuthSecret = TwitterInfos.OAUTH_SECRET.getCredentialValue(); ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(consumerKey); builder.setOAuthConsumerSecret(consumerSecret); builder.setOAuthAccessToken(oAuthToken); builder.setOAuthAccessTokenSecret(oAuthSecret); Configuration configuration = builder.build(); TwitterFactory factory = new TwitterFactory(configuration); Twitter twitter = factory.getInstance(); return twitter; }