List of usage examples for twitter4j.conf ConfigurationBuilder setOAuthConsumerKey
public ConfigurationBuilder setOAuthConsumerKey(String oAuthConsumerKey)
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 w ww. j a v a 2 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: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 w w . j a va 2s. c o m*/ 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 ww . j av a 2 s . com*/ 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.aremaitch.codestock2010.library.TwitterLib.java
License:Apache License
private void buildObject(String consumerKey, String consumerSecret, String accessToken, String accessTokenSecret) { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey(consumerKey).setDebugEnabled(true).setOAuthConsumerSecret(consumerSecret) .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessTokenSecret); Configuration config = cb.build(); t = new TwitterFactory(config).getInstance(); }
From source file:com.arihant15.ActionServlet.java
@RequestMapping("/login.arihant15") public void doLogin(HttpServletRequest req, HttpServletResponse res) { try {//w w w. j av a 2 s . c o m ConfigurationBuilder configuration = new ConfigurationBuilder(); configuration.setOAuthConsumerKey(ConsumerKey); configuration.setOAuthConsumerSecret(ConsumerSecret); TwitterFactory twitterfactory = new TwitterFactory(configuration.build()); Twitter twitter = twitterfactory.getInstance(); req.getSession().setAttribute("t", twitter); RequestToken requestToken = twitter.getOAuthRequestToken(); req.getSession().setAttribute("rToken", requestToken); res.sendRedirect(requestToken.getAuthenticationURL()); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.babatunde.twittergoogle.Utility.java
public Utility() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(""); builder.setOAuthConsumerSecret(""); builder.setOAuthAccessToken(""); builder.setOAuthAccessTokenSecret(""); configuration = builder.build();//from ww w .j av a2 s . c o m }
From source file:com.cloudera.flume.source.TwitterSource.java
License:Apache License
/** * The initialization method for the Source. The context contains all the * Flume configuration info, and can be used to retrieve any configuration * values necessary to set up the Source. *//*from w w w .j a va2 s . c o m*/ @Override public void configure(Context context) { consumerKey = context.getString(TwitterSourceConstants.CONSUMER_KEY_KEY); consumerSecret = context.getString(TwitterSourceConstants.CONSUMER_SECRET_KEY); accessToken = context.getString(TwitterSourceConstants.ACCESS_TOKEN_KEY); accessTokenSecret = context.getString(TwitterSourceConstants.ACCESS_TOKEN_SECRET_KEY); String keywordString = context.getString(TwitterSourceConstants.KEYWORDS_KEY, ""); keywords = keywordString.split(","); for (int i = 0; i < keywords.length; i++) { keywords[i] = keywords[i].trim(); } ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setOAuthConsumerKey(consumerKey); cb.setOAuthConsumerSecret(consumerSecret); cb.setOAuthAccessToken(accessToken); cb.setOAuthAccessTokenSecret(accessTokenSecret); cb.setJSONStoreEnabled(true); cb.setIncludeEntitiesEnabled(true); twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); }
From source file:com.data.dataanalytics.twitter.TwitterFeed.java
private static OAuth2Token getOAuth2Token() { OAuth2Token token = null;// w ww . j a 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:com.data.dataanalytics.twitter.TwitterFeed.java
/** * Get a fully application-authenticated Twitter object useful for making subsequent calls. * *//* w w w .j a v a 2 s. c o m*/ 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.dwdesign.tweetings.activity.TwitterLoginActivity.java
License:Open Source License
private ConfigurationBuilder setAPI(ConfigurationBuilder cb) { final SharedPreferences preferences = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); final boolean enable_gzip_compressing = preferences.getBoolean(PREFERENCE_KEY_GZIP_COMPRESSING, false); final boolean ignore_ssl_error = preferences.getBoolean(PREFERENCE_KEY_IGNORE_SSL_ERROR, false); final boolean enable_proxy = preferences.getBoolean(PREFERENCE_KEY_ENABLE_PROXY, false); final String consumer_key = preferences.getString(PREFERENCE_KEY_CONSUMER_KEY, CONSUMER_KEY); final String consumer_secret = preferences.getString(PREFERENCE_KEY_CONSUMER_SECRET, CONSUMER_SECRET); setUserAgent(this, cb); //if (!isNullOrEmpty(rest_base_url)) { cb.setRestBaseURL(DEFAULT_REST_BASE_URL); //}//from www.j av a 2 s . com //if (!isNullOrEmpty(search_base_url)) { cb.setSearchBaseURL(DEFAULT_SEARCH_BASE_URL); //} if (isNullOrEmpty(consumer_key) || isNullOrEmpty(consumer_secret)) { cb.setOAuthConsumerKey(CONSUMER_KEY); cb.setOAuthConsumerSecret(CONSUMER_SECRET); } else { cb.setOAuthConsumerKey(consumer_key); cb.setOAuthConsumerSecret(consumer_secret); } 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); } } return cb; }