List of usage examples for twitter4j Paging setCount
public void setCount(int count)
From source file:alberapps.java.noticias.tw.tw4j.ProcesarTwitter4j.java
License:Open Source License
/** * Recuperar el timeline del usuario indicado * * @param twuser//w ww. j av a 2s . c om * @param url * @param elementos * @return listado */ public List<TwResultado> recuperarTimeline(String twuser, String url, int elementos) throws Exception { List<TwResultado> listaResultados = new ArrayList<>(); Paging pagina = new Paging(); pagina.setCount(elementos); ResponseList<Status> timeline = twitter.getUserTimeline(twuser, pagina); listaResultados = new ArrayList<>(); Status linea = timeline.get(0); TwResultado resultado = null; for (int i = 0; i < timeline.size(); i++) { resultado = new TwResultado(); resultado.setId(Long.toString(timeline.get(i).getId())); resultado.setFechaDate(timeline.get(i).getCreatedAt()); resultado.setFecha(formatearFechaTw(resultado.getFechaDate())); resultado.setNombreCompleto(timeline.get(i).getUser().getName()); resultado.setUsuario("@" + timeline.get(i).getUser().getScreenName()); resultado.setMensaje(timeline.get(i).getText()); resultado.setImagen(timeline.get(i).getUser().getBiggerProfileImageURL()); resultado.setRetweet(timeline.get(i).isRetweet()); // Imagen de perfil // resultado.setImagenBitmap(recuperaImagen(resultado.getImagen())); resultado.setUrl(url); resultado.setRespuestaId(timeline.get(i).getInReplyToUserId()); Log.d("twitter", "resp: " + resultado.getRespuestaId()); listaResultados.add(resultado); } //throw new Exception("prueba"); return listaResultados; }
From source file:collector.TwitterCollector.java
public LinkedHashSet<Tweet> userSearchData(String userName, int maxResults) { LinkedHashSet<Tweet> out = new LinkedHashSet<>(); Paging paging = new Paging(1, 180); int numberOfTweets = maxResults;//512; long lastID = Long.MAX_VALUE; ArrayList<Status> status = new ArrayList<>(); while (status.size() < numberOfTweets) { if (numberOfTweets - status.size() > 180) {//100) { paging.setCount(180);//100); } else {/* w ww . j a va 2s . c om*/ paging.setCount(numberOfTweets - status.size()); } try { List<Status> timeLine = twitter.getUserTimeline(userName, paging); status.addAll(timeLine); for (Status t : status) { if (t.getId() < lastID) { lastID = t.getId(); } } } catch (TwitterException ex) { System.err.println(ex.getMessage()); } paging.setMaxId(lastID - 1); } //armazenar os atributos interessantes a analise dos tweets int qtdretweet = 0; for (Status sta : status) { String text = sta.getText(); if (!sta.isRetweet() && !sta.isRetweeted() && !text.startsWith("RT")) { //&& !TweetMediaDetect.detect(text)) { TwitterUser user; user = new TwitterUser().addID(sta.getUser().getId()).addName(sta.getUser().getName()) .addLocation(sta.getUser().getLocation()).addDateSignin(sta.getUser().getCreatedAt()) .addCountTweets(sta.getUser().getStatusesCount()) .addCountFavorites(sta.getUser().getFavouritesCount()) .addCountFriends(sta.getUser().getFriendsCount()) .addCountFollowers(sta.getUser().getFollowersCount()); Tweet tweet = new Tweet().addUser(user).addText(sta.getText()).addID(sta.getId()) .addDate(sta.getCreatedAt()) .addLatitude(sta.getGeoLocation() != null ? sta.getGeoLocation().getLatitude() : Double.MAX_VALUE) .addLongitude(sta.getGeoLocation() != null ? sta.getGeoLocation().getLongitude() : Double.MAX_VALUE); out.add(tweet); } else { qtdretweet++; } } return out; }
From source file:com.dwdesign.tweetings.loader.Twitter4JStatusLoader.java
License:Open Source License
@SuppressWarnings("unchecked") @Override//from w ww .j a va 2s . c o m public SynchronizedStateSavedList<ParcelableStatus, Long> loadInBackground() { final SynchronizedStateSavedList<ParcelableStatus, Long> data = getData(); List<Status> statuses = null; final Context context = getContext(); final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); final int load_item_limit = prefs.getInt(PREFERENCE_KEY_LOAD_ITEM_LIMIT, PREFERENCE_DEFAULT_LOAD_ITEM_LIMIT); try { final Paging paging = new Paging(); paging.setCount(load_item_limit); if (mMaxId > 0) { paging.setMaxId(mMaxId); } if (mSinceId > 0) { paging.setSinceId(mSinceId); } statuses = getStatuses(paging); } catch (final TwitterException e) { e.printStackTrace(); } if (statuses != null) { final boolean insert_gap = load_item_limit == statuses.size() && data.size() > 0; final Status min_status = statuses.size() > 0 ? Collections.min(statuses) : null; final long min_status_id = min_status != null ? min_status.getId() : -1; for (final Status status : statuses) { final long id = status.getId(); deleteStatus(id); data.add(new ParcelableStatus(status, mAccountId, min_status_id > 0 && min_status_id == id && insert_gap, mInlineImagePreviewDisplayOption == INLINE_IMAGE_PREVIEW_DISPLAY_OPTION_CODE_LARGE_HIGH)); } } try { final List<ParcelableStatus> statuses_to_remove = new ArrayList<ParcelableStatus>(); for (final ParcelableStatus status : data) { if (isFiltered(context, status.screen_name, status.source, status.text_plain) && !status.is_gap) { statuses_to_remove.add(status); } } data.removeAll(statuses_to_remove); Collections.sort(data); } catch (final ConcurrentModificationException e) { Log.w(LOGTAG, e); } return data; }
From source file:com.javielinux.api.loaders.LoadMoreTweetDownLoader.java
License:Apache License
@Override public BaseResponse loadInBackground() { try {// ww w .j ava2 s . com LoadMoreTweetDownResponse response = new LoadMoreTweetDownResponse(); PreferenceManager.setDefaultValues(getContext(), R.xml.preferences, false); SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getContext()); int maxDownloadTweet = Integer.parseInt(pref.getString("prf_n_max_download", "60")); if (maxDownloadTweet <= 0) maxDownloadTweet = 60; ConnectionManager.getInstance().open(getContext()); Twitter twitter = ConnectionManager.getInstance().getTwitter(request.getUserId()); Paging p = new Paging(); p.setCount(maxDownloadTweet); p.setSinceId(request.getSinceId()); p.setMaxId(request.getMaxId()); ResponseList<Status> statii = null; try { statii = twitter.getHomeTimeline(p); } catch (OutOfMemoryError e) { e.printStackTrace(); } boolean breakTimeline = false; if (statii != null && statii.size() >= maxDownloadTweet - 10) { p = new Paging(1, 10); p.setSinceId(request.getSinceId()); p.setMaxId(statii.get(statii.size() - 1).getId()); if (twitter.getHomeTimeline().size() > 0) { breakTimeline = true; response.setHasMoreTweets(true); } } if (statii != null) { if (statii.size() > 0) { try { DataFramework.getInstance().open(getContext(), Utils.packageName); } catch (Exception e) { e.printStackTrace(); } List<InfoTweet> tweets = new ArrayList<InfoTweet>(); for (Status status : statii) { tweets.add(new InfoTweet(status)); } response.setTweets(tweets); long nextId = 1; Cursor c = DataFramework.getInstance().getCursor("tweets_user", new String[] { DataFramework.KEY_ID }, null, null, null, null, DataFramework.KEY_ID + " desc", "1"); if (!c.moveToFirst()) { c.close(); nextId = 1; } else { long Id = c.getInt(0) + 1; c.close(); nextId = Id; } try { boolean isFirst = true; for (int i = statii.size() - 1; i >= 0; i--) { User u = statii.get(i).getUser(); if (u != null) { ContentValues args = new ContentValues(); args.put(DataFramework.KEY_ID, "" + nextId); args.put("type_id", TweetTopicsUtils.TWEET_TYPE_TIMELINE); args.put("user_tt_id", "" + request.getUserId()); if (u.getProfileImageURL() != null) { args.put("url_avatar", u.getProfileImageURL().toString()); } else { args.put("url_avatar", ""); } args.put("username", u.getScreenName()); args.put("fullname", u.getName()); args.put("user_id", "" + u.getId()); args.put("tweet_id", Utils.fillZeros("" + statii.get(i).getId())); args.put("source", statii.get(i).getSource()); args.put("to_username", statii.get(i).getInReplyToScreenName()); args.put("to_user_id", "" + statii.get(i).getInReplyToUserId()); args.put("date", String.valueOf(statii.get(i).getCreatedAt().getTime())); if (statii.get(i).getRetweetedStatus() != null) { args.put("is_retweet", 1); args.put("retweet_url_avatar", statii.get(i).getRetweetedStatus().getUser() .getProfileImageURL().toString()); args.put("retweet_username", statii.get(i).getRetweetedStatus().getUser().getScreenName()); args.put("retweet_source", statii.get(i).getRetweetedStatus().getSource()); String t = Utils.getTwitLoger(statii.get(i).getRetweetedStatus()); if (t.equals("")) { args.put("text", statii.get(i).getRetweetedStatus().getText()); args.put("text_urls", Utils.getTextURLs(statii.get(i).getRetweetedStatus())); } else { args.put("text", t); } args.put("is_favorite", 0); } else { String t = Utils.getTwitLoger(statii.get(i)); if (t.equals("")) { args.put("text", statii.get(i).getText()); args.put("text_urls", Utils.getTextURLs(statii.get(i))); } else { args.put("text", t); } if (statii.get(i).isFavorited()) { args.put("is_favorite", 1); } } if (statii.get(i).getGeoLocation() != null) { args.put("latitude", statii.get(i).getGeoLocation().getLatitude()); args.put("longitude", statii.get(i).getGeoLocation().getLongitude()); } args.put("reply_tweet_id", statii.get(i).getInReplyToStatusId()); if (breakTimeline && isFirst) args.put("has_more_tweets_down", 1); DataFramework.getInstance().getDB().insert("tweets_user", null, args); nextId++; if (isFirst) isFirst = false; } } } catch (SQLException e) { e.printStackTrace(); } DataFramework.getInstance().close(); } } return response; } catch (TwitterException twitterException) { twitterException.printStackTrace(); ErrorResponse errorResponse = new ErrorResponse(); errorResponse.setError(twitterException, twitterException.getMessage()); return errorResponse; } catch (Exception exception) { exception.printStackTrace(); ErrorResponse errorResponse = new ErrorResponse(); errorResponse.setError(exception, exception.getMessage()); return errorResponse; } }
From source file:com.javielinux.database.EntityTweetUser.java
License:Apache License
public InfoSaveTweets saveTweets(Context context, Twitter twitter) { InfoSaveTweets out = new InfoSaveTweets(); try {/* w ww . jav a 2 s . c o m*/ String where = "type_id = " + tweet_type + " AND user_tt_id=" + getId(); int nResult = DataFramework.getInstance().getEntityListCount("tweets_user", where); if (nResult > 0) mLastIdNotification = DataFramework.getInstance().getTopEntity("tweets_user", where, "date desc") .getLong("tweet_id"); boolean breakTimeline = false; PreferenceManager.setDefaultValues(context, R.xml.preferences, false); SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context); int maxDownloadTweet = Integer.parseInt(pref.getString("prf_n_max_download", "60")); if (maxDownloadTweet <= 0) maxDownloadTweet = 60; ResponseList<twitter4j.Status> statii = null; ResponseList<twitter4j.DirectMessage> directs = null; if (mLastIdNotification > 0) { if (tweet_type == TweetTopicsUtils.TWEET_TYPE_TIMELINE) { Paging p = new Paging(1, maxDownloadTweet); p.setSinceId(mLastIdNotification); try { statii = twitter.getHomeTimeline(p); } catch (OutOfMemoryError e) { e.printStackTrace(); } if (statii != null && statii.size() >= maxDownloadTweet - 10) { p = new Paging(1, 10); p.setSinceId(mLastIdNotification); p.setMaxId(statii.get(statii.size() - 1).getId()); if (twitter.getHomeTimeline().size() > 0) { breakTimeline = true; } } } else if (tweet_type == TweetTopicsUtils.TWEET_TYPE_MENTIONS) { Paging p = new Paging(); p.setCount(100); p.setSinceId(mLastIdNotification); statii = twitter.getMentionsTimeline(p); } else if (tweet_type == TweetTopicsUtils.TWEET_TYPE_DIRECTMESSAGES) { Paging p = new Paging(); p.setCount(100); p.setSinceId(mLastIdNotification); directs = twitter.getDirectMessages(p); } else if (tweet_type == TweetTopicsUtils.TWEET_TYPE_SENT_DIRECTMESSAGES) { Paging p = new Paging(); p.setCount(100); p.setSinceId(mLastIdNotification); directs = twitter.getSentDirectMessages(p); } } else { try { Log.d(Utils.TAG, "Primera carga de " + getTypeText()); if (tweet_type == TweetTopicsUtils.TWEET_TYPE_TIMELINE) { statii = twitter.getHomeTimeline(new Paging(1, 40)); } else if (tweet_type == TweetTopicsUtils.TWEET_TYPE_MENTIONS) { statii = twitter.getMentionsTimeline(new Paging(1, 40)); } else if (tweet_type == TweetTopicsUtils.TWEET_TYPE_DIRECTMESSAGES) { directs = twitter.getDirectMessages(); } else if (tweet_type == TweetTopicsUtils.TWEET_TYPE_SENT_DIRECTMESSAGES) { directs = twitter.getSentDirectMessages(); } } catch (OutOfMemoryError e) { e.printStackTrace(); } } // guardar statii if (statii != null) { if (statii.size() > 0) { out.setNewMessages(statii.size()); out.setNewerId(statii.get(0).getId()); out.setOlderId(statii.get(statii.size() - 1).getId()); Log.d(Utils.TAG, statii.size() + " mensajes nuevos en " + getTypeText() + " de " + getString("name")); long nextId = 1; Cursor c = DataFramework.getInstance().getCursor("tweets_user", new String[] { DataFramework.KEY_ID }, null, null, null, null, DataFramework.KEY_ID + " desc", "1"); if (!c.moveToFirst()) { c.close(); nextId = 1; } else { long Id = c.getInt(0) + 1; c.close(); nextId = Id; } DataFramework.getInstance().getDB().beginTransaction(); try { boolean isFirst = true; for (int i = statii.size() - 1; i >= 0; i--) { User u = statii.get(i).getUser(); if (u != null) { ContentValues args = new ContentValues(); args.put(DataFramework.KEY_ID, "" + nextId); args.put("type_id", tweet_type); args.put("user_tt_id", "" + getId()); if (u.getProfileImageURL() != null) { args.put("url_avatar", u.getProfileImageURL().toString()); } else { args.put("url_avatar", ""); } args.put("username", u.getScreenName()); args.put("fullname", u.getName()); args.put("user_id", "" + u.getId()); args.put("tweet_id", Utils.fillZeros("" + statii.get(i).getId())); args.put("source", statii.get(i).getSource()); args.put("to_username", statii.get(i).getInReplyToScreenName()); args.put("to_user_id", "" + statii.get(i).getInReplyToUserId()); args.put("date", String.valueOf(statii.get(i).getCreatedAt().getTime())); if (statii.get(i).getRetweetedStatus() != null) { args.put("is_retweet", 1); args.put("retweet_url_avatar", statii.get(i).getRetweetedStatus().getUser() .getProfileImageURL().toString()); args.put("retweet_username", statii.get(i).getRetweetedStatus().getUser().getScreenName()); args.put("retweet_source", statii.get(i).getRetweetedStatus().getSource()); String t = Utils.getTwitLoger(statii.get(i).getRetweetedStatus()); if (t.equals("")) { args.put("text", statii.get(i).getRetweetedStatus().getText()); args.put("text_urls", Utils.getTextURLs(statii.get(i).getRetweetedStatus())); } else { args.put("text", t); } args.put("is_favorite", 0); } else { String t = Utils.getTwitLoger(statii.get(i)); if (t.equals("")) { args.put("text", statii.get(i).getText()); args.put("text_urls", Utils.getTextURLs(statii.get(i))); } else { args.put("text", t); } if (statii.get(i).isFavorited()) { args.put("is_favorite", 1); } } if (statii.get(i).getGeoLocation() != null) { args.put("latitude", statii.get(i).getGeoLocation().getLatitude()); args.put("longitude", statii.get(i).getGeoLocation().getLongitude()); } args.put("reply_tweet_id", statii.get(i).getInReplyToStatusId()); if (breakTimeline && isFirst) args.put("has_more_tweets_down", 1); DataFramework.getInstance().getDB().insert("tweets_user", null, args); out.addId(nextId); nextId++; if (isFirst) isFirst = false; } } // finalizar int total = nResult + statii.size(); if (total > Utils.MAX_ROW_BYSEARCH && getValueNewCount() < Utils.MAX_ROW_BYSEARCH || total > Utils.MAX_ROW_BYSEARCH_FORCE) { try { Log.d(Utils.TAG, "Limpiando base de datos de " + getTypeText() + " actualmente " + total + " registros"); String date = DataFramework.getInstance() .getEntityList("tweets_user", "type_id=" + tweet_type + " and user_tt_id=" + getId(), "date desc") .get(Utils.MAX_ROW_BYSEARCH).getString("date"); String sqldelete = "DELETE FROM tweets_user WHERE type_id=" + tweet_type + " and user_tt_id=" + getId() + " AND date < '" + date + "'"; DataFramework.getInstance().getDB().execSQL(sqldelete); } catch (OutOfMemoryError e) { } } DataFramework.getInstance().getDB().setTransactionSuccessful(); } catch (SQLException e) { e.printStackTrace(); } finally { DataFramework.getInstance().getDB().endTransaction(); } } } // guardar directs if (directs != null) { if (directs.size() > 0) { out.setNewMessages(directs.size()); out.setNewerId(directs.get(0).getId()); out.setOlderId(directs.get(directs.size() - 1).getId()); Log.d(Utils.TAG, directs.size() + " mensajes directos a " + getString("name")); long nextId = 1; Cursor c = DataFramework.getInstance().getCursor("tweets_user", new String[] { DataFramework.KEY_ID }, null, null, null, null, DataFramework.KEY_ID + " desc", "1"); if (!c.moveToFirst()) { c.close(); nextId = 1; } else { long Id = c.getInt(0) + 1; c.close(); nextId = Id; } DataFramework.getInstance().getDB().beginTransaction(); try { for (int i = directs.size() - 1; i >= 0; i--) { User u = directs.get(i).getSender(); if (u != null) { ContentValues args = new ContentValues(); args.put(DataFramework.KEY_ID, "" + nextId); args.put("type_id", tweet_type); args.put("user_tt_id", "" + getId()); if (u.getProfileImageURL() != null) { args.put("url_avatar", u.getProfileImageURL().toString()); } else { args.put("url_avatar", ""); } args.put("username", u.getScreenName()); args.put("fullname", u.getName()); args.put("user_id", "" + u.getId()); args.put("tweet_id", Utils.fillZeros("" + directs.get(i).getId())); args.put("source", ""); args.put("to_username", directs.get(i).getRecipientScreenName()); args.put("to_user_id", "" + directs.get(i).getRecipientId()); args.put("date", String.valueOf(directs.get(i).getCreatedAt().getTime())); args.put("text", directs.get(i).getText()); DataFramework.getInstance().getDB().insert("tweets_user", null, args); out.addId(nextId); Log.d(Utils.TAG, "getRecipientScreenName: " + directs.get(i).getRecipientScreenName()); nextId++; } } // finalizar int total = nResult + directs.size(); if (total > Utils.MAX_ROW_BYSEARCH && getValueNewCount() < Utils.MAX_ROW_BYSEARCH) { Log.d(Utils.TAG, "Limpiando base de datos de " + getTypeText() + " actualmente " + total + " registros"); String date = DataFramework.getInstance() .getEntityList("tweets_user", "type_id=" + tweet_type + " and user_tt_id=" + getId(), "date desc") .get(Utils.MAX_ROW_BYSEARCH).getString("date"); String sqldelete = "DELETE FROM tweets_user WHERE type_id=" + tweet_type + " and user_tt_id=" + getId() + " AND date < '" + date + "'"; DataFramework.getInstance().getDB().execSQL(sqldelete); } DataFramework.getInstance().getDB().setTransactionSuccessful(); } catch (SQLException e) { e.printStackTrace(); } finally { DataFramework.getInstance().getDB().endTransaction(); } } } } catch (TwitterException e) { e.printStackTrace(); RateLimitStatus rate = e.getRateLimitStatus(); if (rate != null) { out.setError(Utils.LIMIT_ERROR); out.setRate(rate); } else { out.setError(Utils.UNKNOWN_ERROR); } } catch (Exception e) { e.printStackTrace(); out.setError(Utils.UNKNOWN_ERROR); } return out; }
From source file:com.joshlong.esb.springintegration.modules.social.twitter.TwitterMessageSource.java
License:Apache License
public Message<Tweet> receive() { Assert.state(this.twitterMessageType != null, "the twitterMessageType can't be null!"); Assert.state(cachedStatuses != null, "the cachedStatuses can't be null!"); if (cachedStatuses.peek() == null) { Paging paging = new Paging(); paging.setCount(getPagingCount()); if (-1 != lastStatusIdRetreived) { paging.sinceId(lastStatusIdRetreived); }//from ww w .j a va 2 s . c om try { List<Status> statuses = new ArrayList<Status>(); switch (getTwitterMessageType()) { case DM: throw new UnsupportedOperationException("we don't support receiving direct mentions yet!"); case FRIENDS: statuses = twitter.getFriendsTimeline(paging); break; case MENTIONS: statuses = twitter.getMentions(paging); break; } if (cachedStatuses.peek() == null) { for (Status status : statuses) { this.cachedStatuses.add(buildTweetFromStatus(status)); } } } catch (TwitterException e) { logger.info(ExceptionUtils.getFullStackTrace(e)); throw new RuntimeException(e); } } if (cachedStatuses.peek() != null) { // size() == 0 would be more obvious a test, but size() isn't constant time Tweet cachedStatus = cachedStatuses.poll(); lastStatusIdRetreived = cachedStatus.getTweetId(); return MessageBuilder.withPayload(cachedStatus).build(); } return null; }
From source file:com.marpies.ane.twitter.functions.GetDirectMessagesFunction.java
License:Apache License
private Paging getPaging(int count, long sinceID, long maxID) { Paging paging = null; if (count != 20) { paging = new Paging(); paging.setCount(count); }//from www. j a va2 s . c o m if (sinceID >= 0) { paging = (paging == null) ? new Paging() : paging; paging.setSinceId(sinceID); } if (maxID >= 0) { paging = (paging == null) ? new Paging() : paging; paging.setMaxId(maxID); } return paging; }
From source file:com.marpies.ane.twitter.functions.GetSentDirectMessagesFunction.java
License:Apache License
private Paging getPaging(int count, long sinceID, long maxID, int page) { Paging paging = null; if (count != 20) { paging = new Paging(); paging.setCount(count); }//from ww w. j av a 2 s. c om if (sinceID >= 0) { paging = (paging == null) ? new Paging() : paging; paging.setSinceId(sinceID); } if (maxID >= 0) { paging = (paging == null) ? new Paging() : paging; paging.setMaxId(maxID); } if (page > 0) { paging = (paging == null) ? new Paging() : paging; paging.setPage(page); } return paging; }
From source file:com.stronquens.amgtwitter.ControllerTwitter.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*w w w . j a v a2 s. com*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { // Obtenemos parametros de la peticion String op = request.getParameter("op"); String accesToken = request.getParameter("token"); String accesTokenSecret = request.getParameter("secret"); // Inicializamos variables String jsonResult = ""; Twitter twitter = null; ConfigurationBuilder configBuilder = new ConfigurationBuilder(); Gson gson = new GsonBuilder().setDateFormat("dd/MM/yyyy HH:mm:ss").create(); // Se crea la instancia de twitter segun los parametros de ususario if (!"".equalsIgnoreCase(accesToken) && !"".equalsIgnoreCase(accesTokenSecret)) { try { configBuilder.setDebugEnabled(true).setOAuthConsumerKey("nyFJnGU5NfN7MLuGufXhAcPTf") .setOAuthConsumerSecret("QOofP3lOC7ytKutfoexCyh3zDVIFNHoMuuuKI98S78XmeGvqgW") .setOAuthAccessToken(accesToken).setOAuthAccessTokenSecret(accesTokenSecret); twitter = new TwitterFactory(configBuilder.build()).getInstance(); } catch (Exception e) { System.out.println(e); } } else { try { configBuilder.setDebugEnabled(true).setOAuthConsumerKey("nyFJnGU5NfN7MLuGufXhAcPTf") .setOAuthConsumerSecret("QOofP3lOC7ytKutfoexCyh3zDVIFNHoMuuuKI98S78XmeGvqgW"); twitter = new TwitterFactory(configBuilder.build()).getInstance(); } catch (Exception e) { System.out.println(e); } } // Se realizan las diferentes operaciones switch (op) { case "timeline": try { Paging pagina = new Paging(); pagina.setCount(25); ResponseList listado = twitter.getHomeTimeline(pagina); jsonResult = gson.toJson(listado); } catch (TwitterException ex) { System.out.println(ex); } break; case "usersettings": try { jsonResult = gson.toJson(twitter.showUser(twitter.getId())); } catch (TwitterException ex) { System.out.println(ex); } break; case "pruebas": try { jsonResult = gson.toJson(twitter.showUser(twitter.getId())); } catch (TwitterException ex) { System.out.println(ex); } break; default: jsonResult = "{\"eror\":\"la operacion no existe\"}"; } // Se devuelven los valores out.println(jsonResult); } }
From source file:com.vodafone.twitter.service.TwitterService.java
License:Apache License
private int fetchHomeTimeline() { // retrieve the latest up to maxQueueMessages twt-msgs int count = 0, countProcessed = 0; if (twitter != null) { List<Status> statuses = null; try {// w w w . j a v a2 s .c o m int messageListSize = 0; Paging paging = new Paging(); paging.setCount(maxQueueMessages); if (Config.LOGD) Log.i(LOGTAG, String.format("fetchHomeTimeline() twitter.getHomeTimeline() maxQueueMessages=%d", maxQueueMessages)); statuses = twitter.getHomeTimeline(paging); if (statuses != null) { count = statuses.size(); for (Status status : statuses) { if (processStatus(status)) countProcessed++; } synchronized (messageList) { messageListSize = messageList.size(); } if (Config.LOGD) Log.i(LOGTAG, String.format("fetchHomeTimeline() countProcessed=%d, messageList.size()=%d done", countProcessed, messageListSize)); if (countProcessed > 0) notifyClient(); } else { if (Config.LOGD) Log.i(LOGTAG, "fetchHomeTimeline() no statuses"); } } catch (TwitterException twex) { Log.e(LOGTAG, "fetchHomeTimeline() failed to get twitter timeline: " + twex); errMsg = twex.getMessage(); } catch (java.lang.IllegalStateException illstaex) { Log.e(LOGTAG, "fetchHomeTimeline() IllegalStateException illstaex=" + illstaex); errMsg = "IllegalStateException on .getHomeTimeline()"; } } return count; }