List of usage examples for twitter4j.conf ConfigurationBuilder ConfigurationBuilder
ConfigurationBuilder
From source file:com.rsinghal.cep.sample.twitter.TwitterBot.java
License:Apache License
public void start() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setJSONStoreEnabled(true);/* w ww. j a v a 2 s .c o m*/ twitter = new TwitterFactory(cb.build()).getInstance(); twitter.setOAuthConsumer(consumerKey, consumerSecret); twitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret)); userIdsToTrack = new long[trackTerms.size()]; for (int i = 0; i < trackTerms.size(); i++) { try { String screenName = StringUtils.substringAfter(trackTerms.get(i), "@"); logger.info("Fetching user ID for - " + screenName); userIdsToTrack[i] = twitter.showUser(screenName).getId(); } catch (TwitterException e) { // TODO Auto-generated catch block e.printStackTrace(); } } // twitter = null; twitterStream.setOAuthConsumer(consumerKey, consumerSecret); twitterStream.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret)); twitterStream.addListener(listener2); // sample() method internally creates a thread which manipulates TwitterStream and calls these adequate listener methods continuously. twitterStream.filter(new FilterQuery(0, userIdsToTrack, trackTerms.toArray(new String[trackTerms.size()]))); jedis = new Jedis(redisHostname, redisPort, 1800); jedis.connect(); System.out.println("start() ..."); /* // Create an appropriately sized blocking queue BlockingQueue<String> queue = new LinkedBlockingQueue<String>(10000); // create the endpoint DefaultStreamingEndpoint endpoint = createEndpoint(); System.out.println("endpoint created ..."); endpoint.stallWarnings(false); // create an authentication Authentication auth = new OAuth1(consumerKey, consumerSecret, accessToken, accessTokenSecret); // Create a new BasicClient. By default gzip is enabled. client = new ClientBuilder().name("sampleExampleClient") .hosts(Constants.STREAM_HOST).endpoint(endpoint) .authentication(auth) .processor(new StringDelimitedProcessor(queue)).build(); System.out.println("client created ..."); // Create an executor service which will spawn threads to do the actual // work of parsing the incoming messages and // calling the listeners on each message ExecutorService service = Executors .newFixedThreadPool(this.numberOfProcessingThreads); // Wrap our BasicClient with the twitter4j client Twitter4jStatusClient t4jClient = new Twitter4jStatusClient(client, queue, Lists.newArrayList(listener2), service); // Establish a connection t4jClient.connect(); System.out.println("connection established ..."); for (int threads = 0; threads < this.numberOfProcessingThreads; threads++) { // This must be called once per processing thread t4jClient.process(); System.out.println("thread " + threads + " started ..."); }*/ }
From source file:com.saugereau.spout.TwitterSpout.java
License:Apache License
@Override public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) { queue = new LinkedBlockingQueue<Status>(1000); _collector = collector;//from w w w .jav a 2s. co m StatusListener listener = new StatusListener() { @Override public void onStatus(Status status) { queue.offer(status); } @Override public void onDeletionNotice(StatusDeletionNotice sdn) { } @Override public void onTrackLimitationNotice(int i) { LOG.info("Got track limitation notice:" + i); } @Override public void onScrubGeo(long l, long l1) { } @Override public void onException(Exception ex) { ex.printStackTrace(); } @Override public void onStallWarning(StallWarning arg0) { // TODO Auto-generated method stub } }; _twitterStream = new TwitterStreamFactory(new ConfigurationBuilder().setJSONStoreEnabled(true).build()) .getInstance(); _twitterStream.addListener(listener); _twitterStream.setOAuthConsumer(consumerKey, consumerSecret); AccessToken token = new AccessToken(accessToken, accessTokenSecret); _twitterStream.setOAuthAccessToken(token); if (keyWords.length == 0) { _twitterStream.sample(); } else { FilterQuery query = new FilterQuery().track(keyWords); query.language(new String[] { "en" }); _twitterStream.filter(query); } }
From source file:com.sinfonier.drains.TweetIt.java
License:Apache License
@Override public void userexecute() { ConfigurationBuilder config = new ConfigurationBuilder(); config.setOAuthConsumerKey(this.CONSUMER_KEY); config.setOAuthConsumerSecret(this.CONSUMER_SECRET); config.setOAuthAccessToken(this.ACCESS_TOKEN); config.setOAuthAccessTokenSecret(this.ACCESS_TOKEN_SECRET); config.setJSONStoreEnabled(true);/*from www . ja va 2 s .c om*/ config.setIncludeEntitiesEnabled(true); try { TwitterFactory tf = new TwitterFactory(config.build()); Twitter twitter = tf.getInstance(); Status status = twitter.updateStatus(this.customText + " " + this.getField(this.fieldToTweet)); System.out.println("Successfully updated the status to [" + status.getText() + "]."); } catch (TwitterException te) { te.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.sinfonier.spouts.Twitter.java
License:Apache License
/** * Create a TwitterStream. Requires Twitter API keys. * //from w ww .j a va 2 s. c o m * @return {@link twitter4j.TwitterStream} */ private TwitterStream createTwitterStream() { ConfigurationBuilder config = new ConfigurationBuilder(); config.setOAuthConsumerKey(xml.get(CONSUMER_KEY, true)); config.setOAuthConsumerSecret(xml.get(CONSUMER_SECRET, true)); config.setOAuthAccessToken(xml.get(ACCESS_TOKEN, true)); config.setOAuthAccessTokenSecret(xml.get(ACCESS_TOKEN_SECRET, true)); config.setJSONStoreEnabled(true); config.setIncludeEntitiesEnabled(true); return new TwitterStreamFactory(config.build()).getInstance(); }
From source file:com.smart.home.service.TwitterService.java
License:Open Source License
/** * Constructor for twitter service/*from w w w.jav a2s. co m*/ * * @param apiKey twitter API key * @param apiSecret twitter API secret key * @param token twitter access token * @param tokenSecret twitter access token secret */ public TwitterService(String apiKey, String apiSecret, String token, String tokenSecret) { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(apiKey).setOAuthConsumerSecret(apiSecret) .setOAuthAccessToken(token).setOAuthAccessTokenSecret(tokenSecret); TwitterFactory factory = new TwitterFactory(cb.build()); twitter = factory.getInstance(); twitter.directMessages(); }
From source file:com.social.solution.fragment.MyFragment.java
License:Apache License
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.tweet_list, container, false); lastTimeStamp = System.currentTimeMillis(); mSwipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh_layout); mSwipeLayout.setProgressViewOffset(false, 150, 200); mSwipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override//from w w w . j a v a 2 s . c om public void onRefresh() { long currentTimeStamp = System.currentTimeMillis(); if ((currentTimeStamp - lastTimeStamp) / 1000 > 10) { System.out.println("load recent pranjal"); LoadRecentTweets(); } } }); Activity parentActivity = getActivity(); Fabric.with(getActivity(), new TweetUi()); Bundle bd = getArguments(); if (bd != null) { filterTweets = bd.getBoolean("filter"); position = bd.getInt("position"); } else { filterTweets = false; position = 0; } //Toast.makeText(this, "Filter : "+filterTweets+" Position : "+position, Toast.LENGTH_SHORT).show(); System.out.println("Filter : " + filterTweets + " Position : " + position); linlaHeaderProgress = (LinearLayout) view.findViewById(R.id.linlaHeaderProgress); listView = (ObservableListView) view.findViewById(R.id.mylist); final EnumSet<RequestParameters.NativeAdAsset> desiredAssets = EnumSet.of( RequestParameters.NativeAdAsset.TITLE, RequestParameters.NativeAdAsset.TEXT, RequestParameters.NativeAdAsset.ICON_IMAGE, RequestParameters.NativeAdAsset.MAIN_IMAGE, RequestParameters.NativeAdAsset.CALL_TO_ACTION_TEXT); mRequestParameters = new RequestParameters.Builder() //.location(location) .keywords("food").desiredAssets(desiredAssets).build(); setmydata(listView, inflater.inflate(R.layout.padding, listView, false)); listView.setAdapter(tweetadapter); linlaHeaderProgress.setBackgroundColor(-1); linlaHeaderProgress.setVisibility(View.VISIBLE); if (parentActivity instanceof ObservableScrollViewCallbacks) { // Scroll to the specified position after layout Bundle args = getArguments(); if (args != null && args.containsKey(ARG_INITIAL_POSITION)) { final int initialPosition = args.getInt(ARG_INITIAL_POSITION, 0); ScrollUtils.addOnGlobalLayoutListener(listView, new Runnable() { @Override public void run() { // scrollTo() doesn't work, should use setSelection() listView.setSelection(initialPosition); } }); } // TouchInterceptionViewGroup should be a parent view other than ViewPager. // This is a workaround for the issue #117: // https://github.com/ksoichiro/Android-ObservableScrollView/issues/117 listView.setTouchInterceptionViewGroup((ViewGroup) parentActivity.findViewById(R.id.root)); listView.setScrollViewCallbacks((ObservableScrollViewCallbacks) parentActivity); } ConfigurationBuilder config = new ConfigurationBuilder().setOAuthConsumerKey(custkey) .setOAuthConsumerSecret(custsecret).setOAuthAccessToken(accesstoken) .setOAuthAccessTokenSecret(accesssecret); twitter1 = new TwitterFactory(config.build()).getInstance(); tweetlist = new ArrayList<Tweet>(); loadingTweets = new ArrayList<Tweet>(); lastDisplayTweetId = Long.MAX_VALUE; firstDisplayTweetId = Long.MIN_VALUE; return view; }
From source file:com.socialnetwork.abhishekchandale.snloginlib.twitter.TwitterSocialNetwork.java
License:Open Source License
private void initTwitterClient() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(mConsumerKey); builder.setOAuthConsumerSecret(mConsumerSecret); String accessToken = mSharedPreferences.getString(SAVE_STATE_KEY_OAUTH_TOKEN, null); String accessTokenSecret = mSharedPreferences.getString(SAVE_STATE_KEY_OAUTH_SECRET, null); TwitterFactory factory = new TwitterFactory(builder.build()); if (TextUtils.isEmpty(accessToken) && TextUtils.isEmpty(accessTokenSecret)) { mTwitter = factory.getInstance(); } else {/*from w w w . java2 s . co m*/ mTwitter = factory.getInstance(new twitter4j.auth.AccessToken(accessToken, accessTokenSecret)); } }
From source file:com.soomla.profile.social.twitter.SoomlaTwitter.java
License:Apache License
/** * {@inheritDoc}//from w w w . java 2 s . co m */ @Override public void configure(Map<String, String> providerParams) { autoLogin = false; if (providerParams != null) { twitterConsumerKey = providerParams.get("consumerKey"); twitterConsumerSecret = providerParams.get("consumerSecret"); // extract autoLogin String autoLoginStr = providerParams.get("autoLogin"); autoLogin = autoLoginStr != null && Boolean.parseBoolean(autoLoginStr); } SoomlaUtils.LogDebug(TAG, String.format("ConsumerKey:%s ConsumerSecret:%s", twitterConsumerKey, twitterConsumerSecret)); if (TextUtils.isEmpty(twitterConsumerKey) || TextUtils.isEmpty(twitterConsumerSecret)) { SoomlaUtils.LogError(TAG, "You must provide the Consumer Key and Secret in the SoomlaProfile initialization parameters"); isInitialized = false; } else { isInitialized = true; } oauthCallbackURL = "oauth://soomla_twitter" + twitterConsumerKey; ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setOAuthConsumerKey(twitterConsumerKey); configurationBuilder.setOAuthConsumerSecret(twitterConsumerSecret); Configuration configuration = configurationBuilder.build(); twitter = new AsyncTwitterFactory(configuration).getInstance(); if (!actionsListenerAdded) { SoomlaUtils.LogWarning(TAG, "added action listener"); twitter.addListener(actionsListener); actionsListenerAdded = true; } }
From source file:com.speed.traquer.app.TraqComplaintTaxi.java
/** * Function to login twitter//from w ww. ja va 2 s . co m * */ private void loginToTwitter() { // Check if already logged in if (!isTwitterLoggedInAlready()) { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY); builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET); Configuration configuration = builder.build(); TwitterFactory factory = new TwitterFactory(configuration); twitter = factory.getInstance(); try { requestToken = twitter.getOAuthRequestToken(TWITTER_CALLBACK_URL); this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(requestToken.getAuthenticationURL()))); } catch (TwitterException e) { e.printStackTrace(); } } else { // user already logged into twitter Toast.makeText(TraqComplaintTaxi.this, "Already Logged into twitter", Toast.LENGTH_SHORT).show(); /* Get Access Token after login*/ /*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); // Getting user details from twitter // For now i am getting his name only twitterID= accessToken.getUserId(); User user = twitter.showUser(twitterID); userName = user.getName(); // Displaying in xml ui //lblUserName.setText(Html.fromHtml("<b>Welcome " + username + "</b>" + description)); } catch (TwitterException e) { // Error in updating status Log.d("Twitter Update Error", e.getMessage()); }*/ } }
From source file:com.speed.traquer.app.TraqComplaintTaxi.java
private void checkTwitterID() { /* Get Access Token after login*/ try {//from w ww . ja v a 2 s .com 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); // Getting user details from twitter // For now i am getting his name only twitterID = accessToken.getUserId(); User user = twitter.showUser(twitterID); userName = user.getName(); //Toast.makeText(TraqComplaintTaxi.this, Long.toString(twitterID) + userName, Toast.LENGTH_SHORT).show(); // Displaying in xml ui //lblUserName.setText(Html.fromHtml("<b>Welcome " + username + "</b>" + description)); } catch (TwitterException e) { // Error in updating status Log.d("Twitter Update Error", e.getMessage()); } catch (Exception e) { // Error in updating status Log.d("error!", e.getMessage()); } }