List of usage examples for twitter4j.conf ConfigurationBuilder setOAuthAccessTokenSecret
public ConfigurationBuilder setOAuthAccessTokenSecret(String oAuthAccessTokenSecret)
From source file:de.hoesel.dav.buv.twitter.internal.RahmenwerkService.java
License:Open Source License
public Twitter getTwitter() { if (twitter == null) { loadProperties();/* w ww.j a v a 2 s .co m*/ ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(oAuthConsumerKey); builder.setOAuthConsumerSecret(oAuthConsumerSecret); IPreferenceStore preferenceStore = Activator.getDefault().getPreferenceStore(); String accessToken = preferenceStore.getString(PreferenceConstants.OAUTH_ACCESS_TOKEN); String secretToken = preferenceStore.getString(PreferenceConstants.OAUTH_ACCESS_SECRET_TOKEN); if (!accessToken.isEmpty() && !secretToken.isEmpty()) { builder.setOAuthAccessToken(accessToken); builder.setOAuthAccessTokenSecret(secretToken); } Configuration configuration = builder.build(); twitterFactory = new TwitterFactory(configuration); twitter = twitterFactory.getInstance(); } return twitter; }
From source file:de.vanita5.twittnuker.util.Utils.java
License:Open Source License
public static Twitter getTwitterInstance(final Context context, final long accountId, final boolean includeEntities, final boolean includeRetweets, final boolean apacheHttp, final String mediaProvider, final String mediaProviderAPIKey) { if (context == null) return null; final TwittnukerApplication app = TwittnukerApplication.getInstance(context); final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); final int connection_timeout = prefs.getInt(KEY_CONNECTION_TIMEOUT, 10) * 1000; final boolean enableGzip = prefs.getBoolean(KEY_GZIP_COMPRESSING, true); final boolean ignoreSSLError = prefs.getBoolean(KEY_IGNORE_SSL_ERROR, false); final boolean enableProxy = prefs.getBoolean(KEY_ENABLE_PROXY, false); // Here I use old consumer key/secret because it's default key for older // versions/*w w w.ja v a2 s. c o m*/ final String where = Where.equals(new Column(Accounts.ACCOUNT_ID), accountId).getSQL(); final Cursor c = ContentResolverUtils.query(context.getContentResolver(), Accounts.CONTENT_URI, Accounts.COLUMNS, where, null, null); if (c == null) return null; try { if (!c.moveToFirst()) return null; final ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setHostAddressResolverFactory(new TwidereHostResolverFactory(app)); if (apacheHttp) { cb.setHttpClientFactory(new TwidereHttpClientFactory(app)); } cb.setHttpConnectionTimeout(connection_timeout); cb.setGZIPEnabled(enableGzip); cb.setIgnoreSSLError(ignoreSSLError); if (enableProxy) { final String proxy_host = prefs.getString(KEY_PROXY_HOST, null); final int proxy_port = ParseUtils.parseInt(prefs.getString(KEY_PROXY_PORT, "-1")); if (!isEmpty(proxy_host) && proxy_port > 0) { cb.setHttpProxyHost(proxy_host); cb.setHttpProxyPort(proxy_port); } } final String prefConsumerKey = prefs.getString(KEY_CONSUMER_KEY, TWITTER_CONSUMER_KEY_2); final String prefConsumerSecret = prefs.getString(KEY_CONSUMER_SECRET, TWITTER_CONSUMER_SECRET_2); final String apiUrlFormat = c.getString(c.getColumnIndex(Accounts.API_URL_FORMAT)); final String consumerKey = trim(c.getString(c.getColumnIndex(Accounts.CONSUMER_KEY))); final String consumerSecret = trim(c.getString(c.getColumnIndex(Accounts.CONSUMER_SECRET))); final boolean sameOAuthSigningUrl = c.getInt(c.getColumnIndex(Accounts.SAME_OAUTH_SIGNING_URL)) == 1; final boolean noVersionSuffix = c.getInt(c.getColumnIndex(Accounts.NO_VERSION_SUFFIX)) == 1; if (!isEmpty(apiUrlFormat)) { final String versionSuffix = noVersionSuffix ? null : "/1.1/"; cb.setRestBaseURL(getApiUrl(apiUrlFormat, "api", versionSuffix)); cb.setOAuthBaseURL(getApiUrl(apiUrlFormat, "api", "/oauth/")); cb.setUploadBaseURL(getApiUrl(apiUrlFormat, "upload", versionSuffix)); if (!sameOAuthSigningUrl) { cb.setSigningRestBaseURL(DEFAULT_SIGNING_REST_BASE_URL); cb.setSigningOAuthBaseURL(DEFAULT_SIGNING_OAUTH_BASE_URL); cb.setSigningUploadBaseURL(DEFAULT_SIGNING_UPLOAD_BASE_URL); } } if (isOfficialConsumerKeySecret(context, consumerKey, consumerSecret)) { setMockOfficialUserAgent(context, cb); } else { setUserAgent(context, cb); } if (!isEmpty(mediaProvider)) { cb.setMediaProvider(mediaProvider); } if (!isEmpty(mediaProviderAPIKey)) { cb.setMediaProviderAPIKey(mediaProviderAPIKey); } cb.setIncludeEntitiesEnabled(includeEntities); cb.setIncludeRTsEnabled(includeRetweets); cb.setIncludeReplyCountEnabled(true); cb.setIncludeDescendentReplyCountEnabled(true); switch (c.getInt(c.getColumnIndexOrThrow(Accounts.AUTH_TYPE))) { case Accounts.AUTH_TYPE_OAUTH: case Accounts.AUTH_TYPE_XAUTH: { if (!isEmpty(consumerKey) && !isEmpty(consumerSecret)) { cb.setOAuthConsumerKey(consumerKey); cb.setOAuthConsumerSecret(consumerSecret); } else if (!isEmpty(prefConsumerKey) && !isEmpty(prefConsumerSecret)) { cb.setOAuthConsumerKey(prefConsumerKey); cb.setOAuthConsumerSecret(prefConsumerSecret); } else { cb.setOAuthConsumerKey(TWITTER_CONSUMER_KEY_2); cb.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET_2); } final String token = c.getString(c.getColumnIndexOrThrow(Accounts.OAUTH_TOKEN)); final String tokenSecret = c.getString(c.getColumnIndexOrThrow(Accounts.OAUTH_TOKEN_SECRET)); if (isEmpty(token) || isEmpty(tokenSecret)) return null; cb.setOAuthAccessToken(token); cb.setOAuthAccessTokenSecret(tokenSecret); return new TwitterFactory(cb.build()).getInstance(new AccessToken(token, tokenSecret)); } case Accounts.AUTH_TYPE_BASIC: { final String screenName = c.getString(c.getColumnIndexOrThrow(Accounts.SCREEN_NAME)); final String username = c.getString(c.getColumnIndexOrThrow(Accounts.BASIC_AUTH_USERNAME)); final String loginName = username != null ? username : screenName; final String password = c.getString(c.getColumnIndexOrThrow(Accounts.BASIC_AUTH_PASSWORD)); if (isEmpty(loginName) || isEmpty(password)) return null; return new TwitterFactory(cb.build()).getInstance(new BasicAuthorization(loginName, password)); } case Accounts.AUTH_TYPE_TWIP_O_MODE: { return new TwitterFactory(cb.build()).getInstance(new TwipOModeAuthorization()); } default: { return null; } } } finally { c.close(); } }
From source file:displaygrid.apps.team1100feed.Team1100TweetsServerApp.java
@Override public void init() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true);//from w w w.jav a 2 s . c om cb.setOAuthConsumerKey(CONSUMER_KEY); cb.setOAuthConsumerSecret(CONSUMER_SECRET); cb.setOAuthAccessToken(ACCESS_TOKEN); cb.setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET); streamTeam = new TwitterStreamFactory(cb.build()).getInstance(); streamTeam.addListener(this); streamTeam.user(); }
From source file:edu.uci.ics.asterix.external.util.TwitterUtil.java
License:Apache License
private static ConfigurationBuilder getAuthConfiguration(Map<String, String> configuration) { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true);//from w ww. j a va 2s. c o m String oAuthConsumerKey = configuration.get(AuthenticationConstants.OAUTH_CONSUMER_KEY); String oAuthConsumerSecret = configuration.get(AuthenticationConstants.OAUTH_CONSUMER_SECRET); String oAuthAccessToken = configuration.get(AuthenticationConstants.OAUTH_ACCESS_TOKEN); String oAuthAccessTokenSecret = configuration.get(AuthenticationConstants.OAUTH_ACCESS_TOKEN_SECRET); cb.setOAuthConsumerKey(oAuthConsumerKey); cb.setOAuthConsumerSecret(oAuthConsumerSecret); cb.setOAuthAccessToken(oAuthAccessToken); cb.setOAuthAccessTokenSecret(oAuthAccessTokenSecret); return cb; }
From source file:entities.TwitterFeed.java
public void postTweet() { KeyReader keyreader = new KeyReader(); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey(keyreader.getConsumerKey()); cb.setOAuthConsumerSecret(keyreader.getConsumerSecret()); cb.setOAuthAccessToken(keyreader.getAccessToken()); cb.setOAuthAccessTokenSecret(keyreader.getAccessTokenSecret()); Twitter tf = new TwitterFactory(cb.build()).getInstance(); try {/*from w ww.j a va 2s . c om*/ tf.updateStatus(typeTweet.getText()); System.out.println("tweet post success"); } catch (TwitterException te) { System.out.println("tweet post failed"); te.printStackTrace(); } }
From source file:flight_ranker.Flight_colllector.java
public static void main(String[] args) throws FileNotFoundException, IOException { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true);/* w w w . j ava 2 s . co m*/ cb.setOAuthConsumerKey("Oa6WAzH0j3sgVrP0CNGvxnWA2"); cb.setOAuthConsumerSecret("sLdoFybvJvVFz7Lxbbv9KWQDFeKcVeZAkWDC4QMHnx5lV2OmGE"); cb.setOAuthAccessToken("2691889945-5NOBWKUgT9FiAoyOQSCFg8CLlPRlDMbWcUrJBdK"); cb.setOAuthAccessTokenSecret("J6tA8Sxrtz2JNSFdQwAonbGxNfLNuD9I54Zfvomku3p5t"); TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); StatusListener listener = new StatusListener() { @Override public void onException(Exception arg0) { // TODO Auto-generated method stub } @Override public void onDeletionNotice(StatusDeletionNotice arg0) { // TODO Auto-generated method stub } @Override public void onScrubGeo(long arg0, long arg1) { // TODO Auto-generated method stub } @Override public void onStatus(Status status) { User user = status.getUser(); // gets Username String username = status.getUser().getScreenName(); long followers = user.getFollowersCount(); long retweets = status.getRetweetCount(); long favs = status.getFavoriteCount(); System.out.println("USERNAME--> " + username); System.out.println("FOLLOWERS--> " + followers); String profileLocation = user.getLocation(); // System.out.println("RETWEETS--> "+retweets); // System.out.println("FAVOURITES--> "+favs); System.out.println("LOCATION--> " + profileLocation); long tweetId = status.getId(); System.out.println("TWEET ID--> " + tweetId); String content = status.getText(); System.out.println("TWEET--> " + content + "\n"); BufferedWriter b1 = null, b2, b3, b4, b5, b6, b7 = null; try { //output_file = new BufferedReader(new FileReader("G:\\Sentiwords.txt")); FileWriter f1 = new FileWriter("G:\\flights_data.txt", true); b1 = new BufferedWriter(f1); b1.write("#USERNAME- " + username); b1.newLine(); b1.write("#Followers- " + followers); b1.newLine(); b1.write("#Location- " + profileLocation); b1.newLine(); b1.write("#ID- " + tweetId); b1.newLine(); b1.write("#Tweet- " + content); b1.newLine(); b1.newLine(); tweet_editor modified_tweet = new tweet_editor(content); //tweet_tagger tagged_tweet = new tweet_tagger(modified_tweet.edited_tweet); //System.out.println(tagged_tweet.tagged); sentiment_calculator senti_value = new sentiment_calculator(modified_tweet.edited_tweet); if (content.contains("Indigo")) { System.out.println("indigo"); FileWriter f2 = new FileWriter("G:\\Indigo.txt", true); b2 = new BufferedWriter(f2); b2.write(Double.toString(senti_value.senti_rate)); b2.newLine(); } if (content.contains("Jet")) { System.out.println("jet"); FileWriter f3 = new FileWriter("G:\\jet.txt", true); b3 = new BufferedWriter(f3); b3.write(Double.toString(senti_value.senti_rate)); b3.newLine(); } if (content.contains("Indian")) { System.out.println("indian"); FileWriter f4 = new FileWriter("G:\\Indian.txt", true); b4 = new BufferedWriter(f4); b4.write(Double.toString(senti_value.senti_rate)); b4.newLine(); } if (content.contains("Spicejet")) { System.out.println("spicejet"); FileWriter f5 = new FileWriter("G:\\spicejet.txt", true); b5 = new BufferedWriter(f5); b5.write(Double.toString(senti_value.senti_rate)); b5.newLine(); } if (content.contains("AirAsia")) { System.out.println("airasia"); FileWriter f6 = new FileWriter("G:\\airasia.txt", true); b6 = new BufferedWriter(f6); b6.write(Double.toString(senti_value.senti_rate)); b6.newLine(); } try { //output_file = new BufferedReader(new FileReader("G:\\Sentiwords.txt")); FileWriter f7 = new FileWriter("G:\\flight_senti.txt", true); b7 = new BufferedWriter(f7); b7.write(String.valueOf(senti_value.senti_rate)); b7.newLine(); } catch (IOException e) { e.printStackTrace(); } finally { try { b7.close(); } catch (IOException ex) { Logger.getLogger(Flight_colllector.class.getName()).log(Level.SEVERE, null, ex); } } } catch (IOException e) { e.printStackTrace(); } finally { try { b1.close(); } catch (IOException ex) { Logger.getLogger(Flight_colllector.class.getName()).log(Level.SEVERE, null, ex); } } } @Override public void onTrackLimitationNotice(int arg0) { // TODO Auto-generated method stub } @Override public void onStallWarning(StallWarning sw) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }; FilterQuery fq = new FilterQuery(); String keywords[] = { "Indian Airlines, Indigo Airlines, Indigo Airline , Indian Airline , Spicejet , jetAirways , Jet Airways, Jet Airlines , airasia" }; //we will pass stock related keyword here fq.track(keywords); twitterStream.addListener(listener); twitterStream.filter(fq); }
From source file:gohai.simpletweet.SimpleTweet.java
License:Apache License
protected void createInstance() { ConfigurationBuilder cb = new ConfigurationBuilder(); if (oAuthConsumerKey != null) { cb.setOAuthConsumerKey(oAuthConsumerKey); }//from ww w.j av a 2 s . c o m if (oAuthConsumerSecret != null) { cb.setOAuthConsumerSecret(oAuthConsumerSecret); } if (oAuthAccessToken != null) { cb.setOAuthAccessToken(oAuthAccessToken); } if (oAuthAccessTokenSecret != null) { cb.setOAuthAccessTokenSecret(oAuthAccessTokenSecret); } twitter = new TwitterFactory(cb.build()).getInstance(); }
From source file:it.greenvulcano.gvesb.social.twitter.TwitterSocialAdapterAccount.java
License:Open Source License
/** * This method returns the interface class towards Twitter, already instantiated with the * account's tokens//from w ww . j a v a2 s. c o m * * @return {@link Twitter} */ public Twitter getProxyObject() { if (twitter != null) { return twitter; } else { // setting OAuth tokens ConfigurationBuilder confBuilder = new ConfigurationBuilder(); if (proxy != null) { confBuilder.setHttpProxyHost(proxy.getHttpProxyHost()); confBuilder.setHttpProxyPort(proxy.getHttpProxyPort()); confBuilder.setHttpProxyUser(proxy.getHttpProxyUser()); confBuilder.setHttpProxyPassword(proxy.getHttpProxyPassword()); } confBuilder.setOAuthConsumerKey(consumerKey); confBuilder.setOAuthConsumerSecret(consumerSecret); confBuilder.setOAuthAccessToken(accessToken); confBuilder.setOAuthAccessTokenSecret(accessTokenSecret); Configuration config = confBuilder.build(); // instantiating Twitter object this.twitter = new TwitterFactory(config).getInstance(); } logger.info("got TwitterFactory instance."); return twitter; }
From source file:Jums.AllAPI.java
public static Configuration TwitterConnect() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true);/*from w w w . j a va 2s . c o m*/ cb.setOAuthConsumerKey(CONSUMERKEY); cb.setOAuthConsumerSecret(CONSUMERSECRET); cb.setOAuthAccessToken(TOKEN); cb.setOAuthAccessTokenSecret(TOKENSECRET); return cb.build(); }
From source file:Jums.SearchTweet.java
public void main(PrintWriter out) { try {//from w ww .j a v a2s. c o m ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true); cb.setOAuthConsumerKey(CONSUMERKEY); cb.setOAuthConsumerSecret(CONSUMERSECRET); cb.setOAuthAccessToken(TOKEN); cb.setOAuthAccessTokenSecret(TOKENSECRET); Twitter tw = new TwitterFactory(cb.build()).getInstance(); User user = tw.verifyCredentials(); List<Status> statuses = tw.getHomeTimeline(); for (Status s : statuses) { } } catch (Exception e) { e.printStackTrace(); } }