List of usage examples for twitter4j.conf ConfigurationBuilder ConfigurationBuilder
ConfigurationBuilder
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 a2 s . 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:cojoytuerto.CojoYTuertoFrame.java
public CojoYTuertoFrame() { initComponents();/*ww w.j a va 2 s . co m*/ jTable1.getTableHeader().setReorderingAllowed(false); try { TAuth auth = new TAuth(); } catch (IOException | TwitterException ex) { Logger.getLogger(CojoYTuertoFrame.class.getName()).log(Level.SEVERE, null, ex); } try { // Apertura del fichero y creacion de BufferedReader archivo = new File("auth_file.txt"); fileR = new FileReader(archivo); lecturaTeclado = new BufferedReader(fileR); // Lectura del fichero String linea = new String(); int n = 1; while ((linea = lecturaTeclado.readLine()) != null) { if (n == 1) { //La primera lnea es el Access Token System.out.println(linea); Token = linea; } else if (n == 2) { //La segunda lnea es el Access Token Secret System.out.println(linea); TokenSecret = linea; } n++; } } catch (Exception e) { e.printStackTrace(); } finally { // En el finally cerramos el fichero, para asegurarnos // que se cierra tanto si todo va bien como si salta // una excepcin. try { if (null != fileR) { fileR.close(); } } catch (Exception e2) { e2.printStackTrace(); } } configBuilder = new ConfigurationBuilder(); configBuilder.setDebugEnabled(true).setOAuthConsumerKey("wCWSOW8xHlxfQq24kSxXuXNm9") .setOAuthConsumerSecret("5B1R4bxZv7TcO7Vmq3NvhM3Bo3YcO0qCIJP2vDD9HnOaPL63YD"); configBuilder.setHttpProxyHost("127.0.0.1"); configBuilder.setUseSSL(true); configBuilder.setHttpProxyPort(3128); configBuilder.setOAuthAccessToken(Token).setOAuthAccessTokenSecret(TokenSecret); twitter = new TwitterFactory(configBuilder.build()).getInstance(); }
From source file:cojoytuerto.TAuth.java
public TAuth() throws IOException, TwitterException { //Constructor de la clase File file = new File("auth_file.txt"); if (!file.exists()) { ConfigurationBuilder configBuilder = new ConfigurationBuilder(); configBuilder.setDebugEnabled(true).setOAuthConsumerKey("wCWSOW8xHlxfQq24kSxXuXNm9") .setOAuthConsumerSecret("5B1R4bxZv7TcO7Vmq3NvhM3Bo3YcO0qCIJP2vDD9HnOaPL63YD"); configBuilder.setHttpProxyHost("127.0.0.1"); configBuilder.setUseSSL(true);//w ww . j a va 2s .c om configBuilder.setHttpProxyPort(3128); Twitter OAuthTwitter = new TwitterFactory(configBuilder.build()).getInstance(); RequestToken requestToken = null; AccessToken accessToken = null; String url = null; do { try { requestToken = OAuthTwitter.getOAuthRequestToken(); System.out.println("Request Token obtenido con xito."); System.out.println("Request Token: " + requestToken.getToken()); System.out.println("Request Token secret: " + requestToken.getTokenSecret()); url = requestToken.getAuthorizationURL(); url = url.replace("http://", "https://"); System.out.println("URL:"); System.out.println(url); } catch (TwitterException ex) { Logger.getLogger(TAuth.class.getName()).log(Level.SEVERE, null, ex); } BufferedReader lectorTeclado = new BufferedReader(new InputStreamReader(System.in)); //Abro el navegador. Firefox, en este caso. Runtime runtime = Runtime.getRuntime(); try { runtime.exec("firefox " + url); } catch (Exception e) { } //Nos avisa de que introduciremos el PIN a continuacin System.out.print("Introduce el PIN del navegador y pulsa intro.nn PIN: "); //Leemos el PIN // String pin = lectorTeclado.readLine(); String pin = JOptionPane.showInputDialog(null, "Introduce el PIN del navegador y pulsa intro.nn PIN: "); if (pin.length() > 0) { accessToken = OAuthTwitter.getOAuthAccessToken(requestToken, pin); } else { accessToken = OAuthTwitter.getOAuthAccessToken(requestToken); } } while (accessToken == null); System.out.println("nnAccess Tokens obtenidos con xito."); System.out.println("Access Token: " + accessToken.getToken()); System.out.println("Access Token secret: " + accessToken.getTokenSecret()); FileOutputStream fileOS = null; // File file; String content = accessToken.getToken() + "\n" + accessToken.getTokenSecret(); try { // file = new File("auth_file.txt"); fileOS = new FileOutputStream(file); //Si el archivo no existe, se crea if (!file.exists()) { file.createNewFile(); } //Se obtiene el contenido en Bytes byte[] contentInBytes = content.getBytes(); fileOS.write(contentInBytes); fileOS.flush(); fileOS.close(); System.out.println("Escritura realizada con xito."); } catch (IOException e) { e.printStackTrace(); } finally { try { if (fileOS != null) { fileOS.close(); } } catch (IOException e) { e.printStackTrace(); } } } }
From source file:collector.TwitterCollector.java
public TwitterCollector(List<String> credentials) { ConfigurationBuilder cb = new ConfigurationBuilder(); String OAuthConsumerKey = credentials.get(0); String OAuthConsumerSecret = credentials.get(1); String OAuthAccessToken = credentials.get(2); String OAuthAccessTokenSecret = credentials.get(3); cb.setDebugEnabled(true).setOAuthConsumerKey(OAuthConsumerKey).setOAuthConsumerSecret(OAuthConsumerSecret) .setOAuthAccessToken(OAuthAccessToken).setOAuthAccessTokenSecret(OAuthAccessTokenSecret); // .setJSONStoreEnabled(true); TwitterFactory tf = new TwitterFactory(cb.build()); twitter = tf.getInstance();//ww w. ja va2 s .co m }
From source file:Collector.TwitterConnector.java
public void makeConnection() { try {//from ww w .j a v a2 s . c o m ob = new ConfigurationBuilder(); ob.setJSONStoreEnabled(true); ob.setDebugEnabled(true).setOAuthConsumerKey("EaNDPdbztcAhLEwREWrnXFrbH") .setOAuthConsumerSecret("TfzWIxgGXrgrlpiCAITFMVD1e7i6y6UuP2Z9rHpKIy7ZN35pGQ") .setOAuthAccessToken("4832753560-BLljOptOjTJs8lmbJlvgjSUM9nEQXjyEpKhQart") .setOAuthAccessTokenSecret("cbXs1UMe9mfcCHWdBEj9yV7NgFZ6xgF8w2uzguQs4BTMb"); tf = new TwitterFactory(ob.build()); tw = tf.getInstance(); System.out.println("Connection made"); // return tw; } catch (Exception e) { System.out.println(e.getMessage()); } }
From source file:ColourUs.OAuth.java
public OAuth() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(C2_KEY).setOAuthConsumerSecret(C2_SECRET) .setOAuthAccessToken(A2_TOKEN).setOAuthAccessTokenSecret(A2_SECRET); config = cb.build();// w w w . j av a2 s. c om }
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);/*from w ww .ja va 2 s . c o m*/ builder.setApplicationOnlyAuthEnabled(true); return builder.build(); }
From source file:com.ahuralab.mozaic.auth.TwitterAuthenticator.java
License:Open Source License
public Twitter createTwitter(Context context) { SharedPreferences settings = context.getSharedPreferences(TWITTER_CREDENTIAL, 0); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret) .setOAuthAccessToken(settings.getString("user_key", null)) .setOAuthAccessTokenSecret(settings.getString("user_secret", null)); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance();// www . jav a 2s .com return twitter; }
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 ww . j a va2 s . c om 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.alainesp.fan.sanderson.SummaryFragment.java
License:Open Source License
protected int doWork() { int state = DownloadParseSaveTask.STATE_SUCCESS; try {/*from w w w.ja 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; }