List of usage examples for twitter4j Twitter getUserTimeline
ResponseList<Status> getUserTimeline(String screenName) throws TwitterException;
From source file:br.com.porcelli.hornetq.integration.twitter.stream.reclaimer.AbstractBaseReclaimLostTweets.java
License:Apache License
protected void loadUserTimeline(final Long lastTweetId, final Twitter twitter) throws Exception { try {//ww w .jav a2 s . c o m if (lastTweetId == null) { return; } int page = 1; while (true) { final Paging paging = new Paging(page, lastTweetId); final ResponseList<Status> rl = twitter.getUserTimeline(paging); if (rl.size() == 0) { break; } for (final Status status : rl) { message.postMessage(status, true); } page++; } } catch (Exception e) { exceptionNotifier.notifyException(e); } }
From source file:co.thehotnews.lambda.TheHotNewsSpeechlet.java
License:Open Source License
private SpeechletResponse getCurrentStatus(String name, String screenName) { List<Status> statuses = null; try {// w ww . j av a2 s. co m Twitter twitter = twitterFactory.getInstance(); statuses = twitter.getUserTimeline(screenName); } catch (Exception e) { log.error("Problem getting current status for " + screenName, e); return getErrorResponse(); } Status status = statuses.get(0); String statusText = ResponseUtils.removeUrl(status.getText()); if (statusText == null || statusText.trim().length() == 0) { // assume there was only a link in the tweet. statusText = " a link. "; } String verb = status.isRetweet() ? " retweeted: " : " tweeted: "; String speechText = name + verb + statusText; String cardText = name + verb + status.getText(); String mediaURl = null; if (status.getMediaEntities() != null && status.getMediaEntities().length > 0) { mediaURl = status.getMediaEntities()[0].getMediaURLHttps(); } StandardCard card = new StandardCard(); card.setTitle(APP_NAME); card.setText(cardText); if (mediaURl != null) { Image image = new Image(); image.setLargeImageUrl(mediaURl); card.setImage(image); } // Create the plain text output. PlainTextOutputSpeech speech = new PlainTextOutputSpeech(); speech.setText(speechText); return SpeechletResponse.newTellResponse(speech, card); }
From source file:com.adobe.acs.commons.twitter.impl.TwitterFeedUpdaterImpl.java
License:Apache License
@Override public void updateTwitterFeedComponents(ResourceResolver resourceResolver) { PageManager pageManager = resourceResolver.adaptTo(PageManager.class); List<Resource> twitterResources = findTwitterResources(resourceResolver); for (Resource twitterResource : twitterResources) { Page page = pageManager.getContainingPage(twitterResource); if (page != null) { Twitter client = page.adaptTo(Twitter.class); if (client != null) { try { ValueMap properties = ResourceUtil.getValueMap(twitterResource); String username = properties.get("username", String.class); if (!StringUtils.isEmpty(username)) { log.info("Loading Twitter timeline for user {} for component {}.", username, twitterResource.getPath()); List<Status> statuses = client.getUserTimeline(username); if (statuses != null) { List<String> tweetsList = new ArrayList<String>(statuses.size()); for (Status status : statuses) { tweetsList.add(processTweet(status)); }/* w w w . j a v a 2 s . c om*/ if (tweetsList.size() > 0) { ModifiableValueMap map = twitterResource.adaptTo(ModifiableValueMap.class); map.put("tweets", tweetsList.toArray(new String[tweetsList.size()])); twitterResource.getResourceResolver().commit(); handleReplication(pageManager, twitterResource); } } } } catch (PersistenceException e) { log.error("Exception while updating twitter feed on resource:" + twitterResource.getPath(), e); } catch (ReplicationException e) { log.error( "Exception while replicating twitter feed on resource:" + twitterResource.getPath(), e); } catch (TwitterException e) { log.error("Exception while loading twitter feed on resource:" + twitterResource.getPath(), 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.j ava2 s. c om*/ 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.android.calendar.AllInOneActivity.java
License:Apache License
@Override protected void onCreate(Bundle icicle) { if (Utils.getSharedPreference(this, OtherPreferences.KEY_OTHER_1, false)) { setTheme(R.style.CalendarTheme_WithActionBarWallpaper); }//from ww w .j ava 2s . c o m super.onCreate(icicle); dynamicTheme.onCreate(this); if (icicle != null && icicle.containsKey(BUNDLE_KEY_CHECK_ACCOUNTS)) { mCheckForAccounts = icicle.getBoolean(BUNDLE_KEY_CHECK_ACCOUNTS); } // Launch add google account if this is first time and there are no // accounts yet if (mCheckForAccounts && !Utils.getSharedPreference(this, GeneralPreferences.KEY_SKIP_SETUP, false)) { mHandler = new QueryHandler(this.getContentResolver()); mHandler.startQuery(0, null, Calendars.CONTENT_URI, new String[] { Calendars._ID }, null, null /* selection args */, null /* sort order */); } // This needs to be created before setContentView mController = CalendarController.getInstance(this); // Check and ask for most needed permissions checkAppPermissions(); // Get time from intent or icicle long timeMillis = -1; int viewType = -1; final Intent intent = getIntent(); if (icicle != null) { timeMillis = icicle.getLong(BUNDLE_KEY_RESTORE_TIME); viewType = icicle.getInt(BUNDLE_KEY_RESTORE_VIEW, -1); } else { String action = intent.getAction(); if (Intent.ACTION_VIEW.equals(action)) { // Open EventInfo later timeMillis = parseViewAction(intent); } if (timeMillis == -1) { timeMillis = Utils.timeFromIntentInMillis(intent); } } if (viewType == -1 || viewType > ViewType.MAX_VALUE) { viewType = Utils.getViewTypeFromIntentAndSharedPref(this); } mTimeZone = Utils.getTimeZone(this, mHomeTimeUpdater); Time t = new Time(mTimeZone); t.set(timeMillis); if (DEBUG) { if (icicle != null && intent != null) { Log.d(TAG, "both, icicle:" + icicle.toString() + " intent:" + intent.toString()); } else { Log.d(TAG, "not both, icicle:" + icicle + " intent:" + intent); } } Resources res = getResources(); mHideString = res.getString(R.string.hide_controls); mShowString = res.getString(R.string.show_controls); mOrientation = res.getConfiguration().orientation; if (mOrientation == Configuration.ORIENTATION_LANDSCAPE) { mControlsAnimateWidth = (int) res.getDimension(R.dimen.calendar_controls_width); if (mControlsParams == null) { mControlsParams = new LayoutParams(mControlsAnimateWidth, 0); } mControlsParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); } else { // Make sure width is in between allowed min and max width values mControlsAnimateWidth = Math.max(res.getDisplayMetrics().widthPixels * 45 / 100, (int) res.getDimension(R.dimen.min_portrait_calendar_controls_width)); mControlsAnimateWidth = Math.min(mControlsAnimateWidth, (int) res.getDimension(R.dimen.max_portrait_calendar_controls_width)); } mControlsAnimateHeight = (int) res.getDimension(R.dimen.calendar_controls_height); mHideControls = !Utils.getSharedPreference(this, GeneralPreferences.KEY_SHOW_CONTROLS, true); mIsMultipane = Utils.getConfigBool(this, R.bool.multiple_pane_config); mIsTabletConfig = Utils.getConfigBool(this, R.bool.tablet_config); mShowAgendaWithMonth = Utils.getConfigBool(this, R.bool.show_agenda_with_month); mShowCalendarControls = Utils.getConfigBool(this, R.bool.show_calendar_controls); mShowEventDetailsWithAgenda = Utils.getConfigBool(this, R.bool.show_event_details_with_agenda); mShowEventInfoFullScreenAgenda = Utils.getConfigBool(this, R.bool.agenda_show_event_info_full_screen); mShowEventInfoFullScreen = Utils.getConfigBool(this, R.bool.show_event_info_full_screen); mCalendarControlsAnimationTime = res.getInteger(R.integer.calendar_controls_animation_time); Utils.setAllowWeekForDetailView(mIsMultipane); // setContentView must be called before configureActionBar setContentView(R.layout.all_in_one_material); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mNavigationView = (NavigationView) findViewById(R.id.navigation_view); mFab = (FloatingActionButton) findViewById(R.id.floating_action_button); if (mIsTabletConfig) { mDateRange = (TextView) findViewById(R.id.date_bar); mWeekTextView = (TextView) findViewById(R.id.week_num); } else { mDateRange = (TextView) getLayoutInflater().inflate(R.layout.date_range_title, null); } setupToolbar(viewType); setupNavDrawer(); setupFloatingActionButton(); mHomeTime = (TextView) findViewById(R.id.home_time); mMiniMonth = findViewById(R.id.mini_month); if (mIsTabletConfig && mOrientation == Configuration.ORIENTATION_PORTRAIT) { mMiniMonth.setLayoutParams( new RelativeLayout.LayoutParams(mControlsAnimateWidth, mControlsAnimateHeight)); } mCalendarsList = findViewById(R.id.calendar_list); mMiniMonthContainer = findViewById(R.id.mini_month_container); mSecondaryPane = findViewById(R.id.secondary_pane); // Must register as the first activity because this activity can modify // the list of event handlers in it's handle method. This affects who // the rest of the handlers the controller dispatches to are. mController.registerFirstEventHandler(HANDLER_KEY, this); initFragments(timeMillis, viewType, icicle); // Listen for changes that would require this to be refreshed SharedPreferences prefs = GeneralPreferences.getSharedPreferences(this); prefs.registerOnSharedPreferenceChangeListener(this); mContentResolver = getContentResolver(); //set layout background AnimationDrawable animation = new AnimationDrawable(); animation.addFrame(getResources().getDrawable(R.mipmap.namo1), 5000); animation.addFrame(getResources().getDrawable(R.mipmap.namo2), 10000); animation.addFrame(getResources().getDrawable(R.mipmap.namo3), 15000); animation.addFrame(getResources().getDrawable(R.mipmap.namo4), 20000); animation.addFrame(getResources().getDrawable(R.mipmap.namo7), 25000); animation.addFrame(getResources().getDrawable(R.mipmap.namo8), 30000); animation.addFrame(getResources().getDrawable(R.mipmap.namo9), 35000); animation.addFrame(getResources().getDrawable(R.mipmap.namo10), 40000); animation.addFrame(getResources().getDrawable(R.mipmap.namo11), 45000); animation.addFrame(getResources().getDrawable(R.mipmap.namo12), 50000); animation.addFrame(getResources().getDrawable(R.mipmap.namo13), 55000); animation.addFrame(getResources().getDrawable(R.mipmap.namo14), 60000); animation.addFrame(getResources().getDrawable(R.mipmap.namo15), 65000); animation.addFrame(getResources().getDrawable(R.mipmap.namo16), 70000); animation.addFrame(getResources().getDrawable(R.mipmap.namo17), 75000); animation.addFrame(getResources().getDrawable(R.mipmap.namo18), 80000); animation.addFrame(getResources().getDrawable(R.mipmap.namo19), 85000); animation.addFrame(getResources().getDrawable(R.mipmap.namo20), 90000); animation.setOneShot(false); mDrawerLayout.setBackground(animation); animation.start(); //sharedpreference for get n save tweet tvSlogan = (TextView) findViewById(R.id.modi_Slogan); list = new ArrayList<>(); sharedpreferences = getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE); final SharedPreferences.Editor editor = sharedpreferences.edit(); final Set<String> set = new HashSet<String>(); new Thread(new Runnable() { @Override public void run() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("IXJTMZRCoCPs0pnZfODmpvCem") .setOAuthConsumerSecret("ReF3xJiSdFcePKeFv2or5JFDxERnkgKBjEl1u9tc6zgsmmgvl7") .setOAuthAccessToken("580688604-FsMXIhAgOVLuMvpieiwTFLHAerMvUXmdvvq6Zsal") .setOAuthAccessTokenSecret("93IEkCWSikYPQw6RsjifUu70COSOJumHQyXTFUyhKh1XJ"); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); try { List<Status> statuses; String user; user = "@narendramodi"; statuses = twitter.getUserTimeline(user); Log.i("Status Count", statuses.size() + " Feeds"); for (int i = 0; i < statuses.size(); i++) { Status status = statuses.get(i); set.add(status.getText()); editor.putStringSet("key", set); editor.commit(); Log.i("Tweet Count " + (i + 1), status.getText() + "\n\n"); } } catch (TwitterException te) { te.printStackTrace(); } } }).start(); Set<String> mySet = new HashSet<String>(); mySet = sharedpreferences.getStringSet("key", set); Timer timer = new Timer(); if (mySet != null) { for (final String tweet : mySet) { list.add(tweet); /* Toast.makeText(getApplicationContext(), tweet, Toast.LENGTH_LONG).show();*/ } } //set modi's slogan // list = new ArrayList<>(); /* sharedpreferences= getSharedPreferences(MyPREFERENCES, MODE_PRIVATE); SharedPreferences.Editor editor = sharedpreferences.edit(); for(int i=0;i<slogan.length;i++) editor.putString(slogan + "_" + i, slogan[i]); editor.commit(); Map<String, ?> str = sharedpreferences.getAll(); for (final Map.Entry<String, ?> entry : str.entrySet()) { list.add(entry.getValue().toString()); }*/ getTweet(); getSlogan(); }
From source file:com.avishkar.NewGetFollowersIDs.java
License:Apache License
private static void getStatuses(String screenName, Twitter twitter) { try {/* www . j a v a2s. co m*/ final Gson gson = new Gson(); checkRateLimit("/statuses/user_timeline", twitter); ResponseList<Status> statuses = twitter.getUserTimeline(screenName); for (Status status : statuses) { DBAccess.insertStatus(gson.toJson(status)); } } catch (TwitterException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.bordengrammar.bordengrammarapp.TwitterActivity.java
License:Open Source License
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_twitter); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { setTranslucentStatus(true);/*from w ww . j a va 2s .co m*/ } SystemBarTintManager tintManager = new SystemBarTintManager(this); tintManager.setStatusBarTintEnabled(true); tintManager.setStatusBarTintResource(R.color.bordenpurple); FeedbackSettings feedbackSettings = new FeedbackSettings(); feedbackSettings.setCancelButtonText("Cancel"); feedbackSettings.setSendButtonText("Send"); feedbackSettings.setText("Send feedback to improve the app"); feedbackSettings.setTitle("Feedback"); feedbackSettings.setToast("We value your feedback"); feedBack = new FeedbackDialog(this, "AF-186C1F794D93-1A", feedbackSettings); ActionBar actionBar = getActionBar(); assert actionBar != null; actionBar.setDisplayHomeAsUpEnabled(true); PACKAGE_NAME = getApplicationContext().getPackageName(); //Now lets get down into the twitter ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("Toqp03fcUErG5P8e9nhfsw") .setOAuthConsumerSecret("SEqktstO9h7SqSm7zmcuWlH3bOtElJm1Ds2TFSwFBc") .setOAuthAccessToken("2245935685-U5LMfl4oEcOv6Khw58JZqRdcH2PlABEeUP2JeXj") .setOAuthAccessTokenSecret("uFcGRpCx8aGXdv3AiAkfVImnoLrlNNCUnZ2UtE76Zbnpa"); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); List<Status> statuses = null; String user; user = "bordengrammar"; try { statuses = twitter.getUserTimeline(user); } catch (TwitterException e) { e.printStackTrace(); } assert statuses != null; twitter4j.Status status1 = statuses.get(0); Format formatter = new SimpleDateFormat("MMM d, K:mm"); savePrefs("twitter", status1.getText()); savePrefs("twittertime", formatter.format(status1.getCreatedAt())); twitter4j.Status status2 = statuses.get(1); twitter4j.Status status3 = statuses.get(2); twitter4j.Status status4 = statuses.get(3); twitter4j.Status status5 = statuses.get(4); twitter4j.Status status6 = statuses.get(5); twitter4j.Status status7 = statuses.get(6); twitter4j.Status status8 = statuses.get(7); twitter4j.Status status9 = statuses.get(8); twitter4j.Status status10 = statuses.get(9); TextView time1 = (TextView) findViewById(R.id.time1); TextView time2 = (TextView) findViewById(R.id.time2); TextView time3 = (TextView) findViewById(R.id.time3); TextView time4 = (TextView) findViewById(R.id.time4); TextView time5 = (TextView) findViewById(R.id.time5); TextView time6 = (TextView) findViewById(R.id.time6); TextView time7 = (TextView) findViewById(R.id.time7); TextView time8 = (TextView) findViewById(R.id.time8); TextView time9 = (TextView) findViewById(R.id.time9); TextView time10 = (TextView) findViewById(R.id.time10); time1.setText(formatter.format(status1.getCreatedAt())); time2.setText(formatter.format(status2.getCreatedAt())); time3.setText(formatter.format(status3.getCreatedAt())); time4.setText(formatter.format(status4.getCreatedAt())); time5.setText(formatter.format(status5.getCreatedAt())); time6.setText(formatter.format(status6.getCreatedAt())); time7.setText(formatter.format(status7.getCreatedAt())); time8.setText(formatter.format(status8.getCreatedAt())); time9.setText(formatter.format(status9.getCreatedAt())); time10.setText(formatter.format(status10.getCreatedAt())); TextView text1 = (TextView) findViewById(R.id.text1); TextView text2 = (TextView) findViewById(R.id.text2); TextView text3 = (TextView) findViewById(R.id.text3); TextView text4 = (TextView) findViewById(R.id.text4); TextView text5 = (TextView) findViewById(R.id.text5); TextView text6 = (TextView) findViewById(R.id.text6); TextView text7 = (TextView) findViewById(R.id.text7); TextView text8 = (TextView) findViewById(R.id.text8); TextView text9 = (TextView) findViewById(R.id.text9); TextView text10 = (TextView) findViewById(R.id.text10); text1.setText(readPrefs("twitter")); text2.setText(status2.getText()); text3.setText(status3.getText()); text4.setText(status4.getText()); text5.setText(status5.getText()); text6.setText(status6.getText()); text7.setText(status7.getText()); text8.setText(status8.getText()); text9.setText(status9.getText()); text10.setText(status10.getText()); /* i think i could have used a for loop... oh well i typed it all already. */ }
From source file:com.dvd.codechallenge.Challengue.java
public static Tweets getTweets(String user) throws TwitterException { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("sMYxrCslzDDHGhFn5MSvPMWhw") .setOAuthConsumerSecret("ip8E4OoTGNQetDHz8oTereIsXAnO2cGlgs7Dd2S4lXti4weHAt") .setOAuthAccessToken("451175684-DBydPtZsitmr6EHPVansnVygQXRALCCKnKUqUa4W") .setOAuthAccessTokenSecret("prPHOfZj3IMFrW7ToFbKWJkRjWHM2qlpUdSecEZyuhLvd"); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); List<Status> statuses = twitter.getUserTimeline(user); // System.out.println("Tweets recuperados"); // statuses.forEach(x -> System.out.println(x.getUser().getName() // + "-> " + x.getUser().getScreenName() + ":::" // + x.getText())); Tweets ts = new Tweets(); statuses.forEach(x -> ts.addTweet(x.getText())); return ts;//ww w . ja v a 2s .c om }
From source file:com.epsi.wks.api_wks_back.User.java
@GET @Path("/following/tweet") @Produces("application/json") public List<JSONObject> getUserFollowingsTweets(@PathParam("id") long userID) { Twitter twitter = UtilConfig.getTwitterInstance(); List<JSONObject> followingTweet = new ArrayList<>(); try {/*from w w w.ja v a 2 s. c o m*/ PagableResponseList<twitter4j.User> userList = twitter.getFriendsList(userID, -1); for (twitter4j.User us : userList) { List<Status> statusFollower = twitter.getUserTimeline(us.getId()); for (Status sts : statusFollower) { JSONObject tweet = new JSONObject(); tweet.put("id", sts.getId()); tweet.put("text", sts.getText()); tweet.put("screen_name", sts.getUser().getScreenName()); tweet.put("name", sts.getUser().getName()); tweet.put("image_url", sts.getUser().getProfileImageURL()); followingTweet.add(tweet); } } } catch (TwitterException e) { } System.out.println("array" + String.valueOf(followingTweet.size())); return followingTweet; }
From source file:com.ijuru.tweetgrab.web.GrabServlet.java
License:Open Source License
/** * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) *///from w ww . ja va2s . c om @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); // Get random account List<String> accounts = Context.getOptions().getAccounts(); String randAccount = accounts.get(rand.nextInt(accounts.size())); try { Twitter twitter = Context.getTwitterFactory().getInstance(); ResponseList<Status> tweets = twitter.getUserTimeline(randAccount); if (tweets.size() == 0) { log.warn("No tweets for " + randAccount); out.write(ERROR_MESSAGE); return; } // Pick random tweet Status randomTweet = tweets.get(rand.nextInt(tweets.size())); //long tweetId = randomTweet.getId(); String tweetText = randomTweet.getText(); out.write(tweetText); } catch (TwitterException ex) { log.error(ex); out.write(ERROR_MESSAGE); return; } }