List of usage examples for twitter4j.auth AccessToken AccessToken
public AccessToken(String token, String tokenSecret)
From source file:be.ugent.tiwi.sleroux.newsrec.newsreclib.twitter.UserHelper.java
License:Apache License
public UserHelper() { twitter = TwitterFactory.getSingleton(); AccessToken accessToken = new AccessToken(TwitterCredentialProvider.getAccessToken(), TwitterCredentialProvider.getAccessSecret()); twitter.setOAuthConsumer(TwitterCredentialProvider.get0AuthConsumerKey(), TwitterCredentialProvider.get0AuthConsumerSecret()); twitter.setOAuthAccessToken(accessToken); }
From source file:be.ugent.tiwi.sleroux.newsrec.twittertest.App.java
public static void main(String[] args) throws TwitterException { Twitter twitter = TwitterFactory.getSingleton(); AccessToken accessToken = new AccessToken("2369203675-1Pk99eotzhCznmIgr3iXb670DpsEVQCANuoBHRs", "6ua72cabIzcFsBgE15RVzULeKT44TnIrOIaf9chY9dlWe"); twitter.setOAuthConsumer("tQjT8XvB7OPNTl8qdhchDo3J2", "FXWVS3OEW7omiUDSLpET0aRInoUumGPWRxOVyk7GrhiwcfLBnV"); twitter.setOAuthAccessToken(accessToken); User user = twitter.showUser("billclinton"); System.out.println("id=" + user.getId()); StreamReaderService srs = new StreamReaderService(); srs.readTwitterFeed();//from w w w .ja v a2 s.c o m }
From source file:bluevia.SendSMS.java
License:Apache License
public static void setTwitterStatus(String userEmail, String tweet) { if (tweet != null) { try {/*www . ja va 2 s . co m*/ Properties twitterAccount = Util.getNetworkAccount(userEmail, "TwitterAccount"); if (twitterAccount != null) { String consumer_key = twitterAccount.getProperty("TwitterAccount.consumer_key"); String consumer_secret = twitterAccount.getProperty("TwitterAccount.consumer_secret"); String access_key = twitterAccount.getProperty("TwitterAccount.access_key"); String access_secret = twitterAccount.getProperty("TwitterAccount.access_secret"); Twitter twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(consumer_key, consumer_secret); twitter.setOAuthAccessToken(new AccessToken(access_key, access_secret)); StatusUpdate status = new StatusUpdate(tweet); twitter.updateStatus(status); } } catch (TwitterException te) { te.printStackTrace(); log.severe(te.getMessage()); } catch (Exception e) { log.severe(String.format("Error sending SMS: %s", e.getMessage())); } } }
From source file:br.ufba.dcc.tagcloud.util.TwitterProvider.java
public void start(String user, int max) throws TwitterException { Twitter twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_KEY_SECRET); AccessToken oathAccessToken = new AccessToken(ACCESS_TOKEN, ACCESS_TOKEN_SECRET); twitter.setOAuthAccessToken(oathAccessToken); this.getTweets(twitter, user, max); }
From source file:chillerbot.ChillTweet.java
private void setUpTwitter() throws TwitterException { twitter = new TwitterFactory().getInstance(); if (loadKeys()) { twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_KEY_SECRET); AccessToken oathAccessToken = new AccessToken(ACCESS_TOKEN, ACCESS_TOKEN_SECRET); twitter.setOAuthAccessToken(oathAccessToken); this.homeTimeline = twitter.getHomeTimeline(); } else {/*w w w. j a va 2 s . c o m*/ System.out.println("Authentication failed, check keys."); } }
From source file:Classes.TwitterPull.java
private void init() { this.twitterFactory = new TwitterFactory(); this.twitter = this.twitterFactory.getInstance(); this.twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET); this.twitter.setOAuthAccessToken(new AccessToken(DEFAULT_ACCESS_TOKEN, DEFAULT_ACCESS_TOKEN_SECRET)); retrievedTweets = new ArrayList<>(); }
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 www . ja v a2s. co 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.accumulobook.designs.graph.TwitterGraph.java
License:Apache License
public static void ingest(final String[] args, final BatchWriter writer, int seconds) throws Exception { String token = args[0];// w ww.ja v a 2s . com String tokenSecret = args[1]; String consumerKey = args[2]; String consumerSecret = args[3]; TwitterStream twitterStream = new TwitterStreamFactory().getInstance(); twitterStream.addListener(new TGStatusListener(writer)); AccessToken accessToken = new AccessToken(token, tokenSecret); twitterStream.setOAuthConsumer(consumerKey, consumerSecret); twitterStream.setOAuthAccessToken(accessToken); System.out.println("processing twitter stream ..."); twitterStream.sample(); Thread.sleep(seconds * 1000); System.out.println("shutting down twitter stream."); twitterStream.shutdown(); writer.flush(); }
From source file:com.adisayoga.earthquake.wrapper.EarthquakeTwitter.java
License:Apache License
/** * User sebelumnya telah diberikan ijin untuk menggunakan Twitter. Oleh * karena itu kita mengambil mandat ini dan mengisinya ke helper Twitter4j. * //from ww w . ja va 2 s .c o m * @param listener Listener saat login berhasil/gagal */ public void loginAuthorizedUser(final AuthListener listener) { Log.d(TAG, "Login authorized user..."); String[] tokens = prefs.getTwitterToken(); String token = tokens[0]; String secret = tokens[1]; if (token.equals("") || secret.equals("")) { // Token pada preference kosong, return listener.onAuthFail(); return; } try { // Buat akses token twitter dari mandat yang kita dapat sebelumnya AccessToken accessToken = new AccessToken(token, secret); twitter.setOAuthAccessToken(accessToken); listener.onAuthComplete(); } catch (Exception e) { Log.e(TAG, e.getMessage(), e); listener.onAuthFail(); } }
From source file:com.adisayoga.earthquake.wrapper.EarthquakeTwitter.java
License:Apache License
/** * Mendapatkan nama user Twitter ini.//from ww w . j a va 2 s . c o m * * @return Nama user */ public String getScreenName() { try { String[] tokens = prefs.getTwitterToken(); String token = tokens[0]; String secret = tokens[1]; AccessToken accessToken = new AccessToken(token, secret); twitter.setOAuthAccessToken(accessToken); return twitter.getScreenName(); } catch (IllegalStateException e) { Log.e(TAG, "IllegalStateException", e); return ""; } catch (TwitterException e) { Log.e(TAG, "TwitterException", e); return ""; } }