List of usage examples for twitter4j Status getText
String getText();
From source file:com.isdp.twitterposterandroid.TwitterManager.java
License:Open Source License
public void tweet(String message) { TwitterFactory tf = new TwitterFactory(configuration); Twitter twitter = tf.getInstance();/*from w w w. j a va2s. c om*/ try { Status status = twitter.updateStatus(message); Log.d("Tweet status", "Successfully updated the status to [" + status.getText() + "]."); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.isdp.twitterposterandroid.TwitterManager.java
License:Open Source License
public void startTwitterStream() { TwitterStream twitterStream = new TwitterStreamFactory(configuration).getInstance(); StatusListener listener = new StatusListener() { @Override// www . j ava 2 s . c o m public void onStatus(Status status) { try { Log.d("Text recieved", "@" + status.getUser().getScreenName() + " - " + status.getText() + "\n"); StringTokenizer st = new StringTokenizer(status.getText(), " "); //first token indicates search engine String searchEngine = st.nextToken(); //burn the next random token String randToken = st.nextToken(); //next token indicates max number of results to return int maxResults = Integer.parseInt(st.nextToken()); String searchString = ""; while (st.hasMoreTokens()) { searchString += st.nextToken() + " "; } if (searchEngine.equals(GoogleManager.TAG_YELP)) { String[] results = GoogleManager.getInstance().trySearch(searchString, GoogleManager.SEARCH_YELP); if (results != null) { for (int i = 0; i < results.length && i < maxResults; ++i) { String tweetMsg = Util.truncateString(results[i], TWITTER_CHARACTER_LIMIT); Log.d("Tweeting", tweetMsg); tweet(tweetMsg); } } else if (results == null || results.length == 0) { tweet(Util.generateRandomString(7) + "\n" + "No results found!"); } } else if (searchEngine.equals(GoogleManager.TAG_WIKI)) { String[] results = GoogleManager.getInstance().trySearch(searchString, GoogleManager.SEARCH_WIKI); if (results != null) { for (int i = 0; i < results.length && i < maxResults; ++i) { String tweetMsg = Util.generateRandomString(3) + "\n" + Util.shortenText(results[i]); tweetMsg = Util.truncateString(tweetMsg, TWITTER_CHARACTER_LIMIT); Log.d("Tweeting", tweetMsg); tweet(tweetMsg); } } else if (results == null || results.length == 0) { tweet(Util.generateRandomString(7) + "\n" + "No results found!"); } } } catch (Exception e) { } } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { Log.d("onDeletionNotice", "Got a status deletion notice id:" + statusDeletionNotice.getStatusId()); } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { Log.d("onTrackLimitationNotice", "Got track limitation notice:" + numberOfLimitedStatuses); } @Override public void onScrubGeo(long userId, long upToStatusId) { Log.d("onScrubGeo", "Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId); } @Override public void onStallWarning(StallWarning warning) { Log.d("onStallWarning", "Got stall warning:" + warning); } @Override public void onException(Exception ex) { Log.d("onException", ex.toString()); } }; twitterStream.addListener(listener); FilterQuery tweetFilterQuery = new FilterQuery(); tweetFilterQuery.follow(new long[] { FOLLOW_ID }); twitterStream.filter(tweetFilterQuery); }
From source file:com.javielinux.infos.InfoTweet.java
License:Apache License
public InfoTweet(Status status) { urls = new ArrayList<URLContent>(); mTypeFrom = FROM_STATUS;/*from w w w.ja v a 2 s . c o m*/ id = status.getId(); urlAvatar = status.getUser().getProfileImageURL().toString(); userId = status.getUser().getId(); text = status.getText(); username = status.getUser().getScreenName(); fullname = status.getUser().getName(); source = status.getSource(); toUsername = status.getInReplyToScreenName(); toUserId = status.getInReplyToUserId(); createAt = status.getCreatedAt(); toReplyId = status.getInReplyToStatusId(); favorited = status.isFavorited(); if (status.getGeoLocation() != null) { latitude = status.getGeoLocation().getLatitude(); longitude = status.getGeoLocation().getLongitude(); } if (status.getRetweetedStatus() != null) { retweet = true; urlAvatarRetweet = status.getRetweetedStatus().getUser().getProfileImageURL().toString(); textRetweet = status.getRetweetedStatus().getText(); usernameRetweet = status.getRetweetedStatus().getUser().getScreenName(); fullnameRetweet = status.getRetweetedStatus().getUser().getName(); sourceRetweet = status.getRetweetedStatus().getSource(); } urlTweet = "http://twitter.com/#!/" + username.toLowerCase() + PREFIX_URL_TWITTER + id; calculateLinks(); }
From source file:com.javielinux.utils.Utils.java
License:Apache License
static public String getTwitLoger(twitter4j.Status st) { String out = ""; String link = ""; if (st.getText().contains("(cont) http://t.co/")) { URLEntity[] urls = st.getURLEntities(); if (urls == null || urls.length <= 0) return out; for (URLEntity url : urls) { if (url.getDisplayURL() != null) { if (url.getDisplayURL().contains("tl.gd")) { link = url.getDisplayURL(); }/* w w w . j a va 2s. co m*/ } } if (!link.equals("")) { String id = link.substring(link.lastIndexOf("/") + 1); String strURL = "http://www.twitlonger.com/api_read/" + id; Document doc = null; try { URL url; URLConnection urlConn = null; url = new URL(strURL); urlConn = url.openConnection(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); doc = db.parse(urlConn.getInputStream()); } catch (IOException ioe) { } catch (ParserConfigurationException pce) { } catch (SAXException se) { } if (doc != null) { try { //String content = doc.getElementsByTagName("content").item(0).getChildNodes().getLength()+"";//.getFirstChild().getNodeValue(); String content = ""; NodeList nodes = doc.getElementsByTagName("content").item(0).getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { content += nodes.item(i).getNodeValue(); } if (!content.equals("")) { return content; } } catch (Exception e) { } } } } return out; }
From source file:com.joanzapata.android.twitter.TwitterFragment.java
License:Apache License
@AfterViews void afterViews() { setRetainInstance(true);//from w ww. ja v a2 s . c o m getSherlockActivity().setTitle("@" + followingAccount); listView.setOnEndOfListListener(this); if (adapter == null) adapter = new QuickAdapter<Status>(getSherlockActivity(), R.layout.tweet) { @Override protected void convert(BaseAdapterHelper helper, Status status) { boolean isRetweet = status.isRetweet(); if (isRetweet) status = status.getRetweetedStatus(); helper.setText(tweetText, status.getText()).setVisible(tweetRT, isRetweet) .setText(tweetName, status.getUser().getName()) .setText(tweetDate, dateFormat.format(status.getCreatedAt())) .setImageUrl(tweetAvatar, status.getUser().getProfileImageURL()).linkify(tweetText); } }; listView.setAdapter(adapter); }
From source file:com.joshlong.esb.springintegration.modules.social.twitter.TwitterMessageSource.java
License:Apache License
private Tweet buildTweetFromStatus(Status firstPost) { Tweet tweet = new Tweet(firstPost.getId(), firstPost.getUser().getName(), firstPost.getCreatedAt(), firstPost.getText()); return tweet; }
From source file:com.k42b3.xoxa.TwitterBot.java
License:Open Source License
public ArrayList<Resource> getResources(int limit) { try {// w w w .java2s . c om List<Status> statuses = this.twitter.getFriendsTimeline(); ArrayList<Resource> resources = new ArrayList<Resource>(limit); for (int i = 0; i < statuses.size() && resources.size() < limit; i++) { Status status = statuses.get(i); if (status.getCreatedAt().after(this.getLastUpdated())) { Resource res = new Resource(); res.setId("" + status.getId()); res.setTitle(status.getText()); res.setLink(status.getSource()); res.setDate(status.getCreatedAt()); resources.add(res); } } return resources; } catch (Exception e) { logger.warning(e.getMessage()); return null; } }
From source file:com.klinker.android.twitter.activities.tweet_viewer.fragments.ConversationFragment.java
License:Apache License
public void getReplies(final ListView listView, final long tweetId, final LinearLayout progressSpinner, final HoloTextView none) { Thread getReplies = new Thread(new Runnable() { @Override/*from www . j a va 2 s . c om*/ public void run() { if (!isRunning) { return; } Twitter twitter = Utils.getTwitter(context, settings); replies = new ArrayList<twitter4j.Status>(); try { status = twitter.showStatus(tweetId); if (status.isRetweet()) { status = status.getRetweetedStatus(); } twitter4j.Status replyStatus = twitter.showStatus(status.getInReplyToStatusId()); try { while (!replyStatus.getText().equals("")) { if (!isRunning) { return; } replies.add(replyStatus); Log.v("reply_status", replyStatus.getText()); replyStatus = twitter.showStatus(replyStatus.getInReplyToStatusId()); } } catch (Exception e) { // the list of replies has ended, but we dont want to go to null } } catch (TwitterException e) { e.printStackTrace(); } if (status != null && replies.size() > 0) { replies.add(0, status); } ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { try { if (replies.size() > 0) { ArrayList<twitter4j.Status> reversed = new ArrayList<twitter4j.Status>(); for (int i = replies.size() - 1; i >= 0; i--) { reversed.add(replies.get(i)); } replies = reversed; adapter = new TimelineArrayAdapter(context, replies); listView.setAdapter(adapter); listView.setVisibility(View.VISIBLE); progressSpinner.setVisibility(View.GONE); } else { } } catch (Exception e) { // none and it got the null object } if (status != null) { // everything here worked, so get the discussion on the tweet getDiscussion(listView, tweetId, progressSpinner, none, status); } } }); } }); getReplies.setPriority(7); getReplies.start(); }
From source file:com.klinker.android.twitter.activities.tweet_viewer.fragments.ConversationFragment.java
License:Apache License
public void getDiscussion(final ListView listView, final long tweetId, final LinearLayout progressBar, final HoloTextView none, final Status status) { Log.v("talon_replies", "getting discussion"); if (replies.size() == 0) { replies.add(status);// w w w . ja v a 2 s. c o m } Thread getReplies = new Thread(new Runnable() { @Override public void run() { if (!isRunning) { return; } ArrayList<twitter4j.Status> all = null; Twitter twitter = Utils.getTwitter(context, settings); try { Log.v("talon_replies", "looking for discussion"); long id = status.getId(); String screenname = status.getUser().getScreenName(); query = new Query("@" + screenname + " since_id:" + id); Log.v("talon_replies", "query string: " + query.getQuery()); try { query.setCount(100); } catch (Throwable e) { // enlarge buffer error? query.setCount(30); } QueryResult result = twitter.search(query); Log.v("talon_replies", "result: " + result.getTweets().size()); all = new ArrayList<twitter4j.Status>(); do { Log.v("talon_replies", "do loop repetition"); if (!isRunning) { return; } List<Status> tweets = result.getTweets(); for (twitter4j.Status tweet : tweets) { if (tweet.getInReplyToStatusId() == id) { all.add(tweet); Log.v("talon_replies", tweet.getText()); } } if (all.size() > 0) { for (int i = all.size() - 1; i >= 0; i--) { Log.v("talon_replies", "inserting into arraylist:" + all.get(i).getText()); replies.add(all.get(i)); } all.clear(); ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { progressBar.setVisibility(View.GONE); try { if (replies.size() > 0) { if (adapter == null || adapter.getCount() == 0) { adapter = new TimelineArrayAdapter(context, replies); listView.setAdapter(adapter); listView.setVisibility(View.VISIBLE); } else { Log.v("talon_replies", "notifying adapter change"); adapter.notifyDataSetChanged(); } } else { none.setVisibility(View.VISIBLE); } } catch (Exception e) { // none and it got the null object e.printStackTrace(); listView.setVisibility(View.GONE); none.setVisibility(View.VISIBLE); } } }); } try { Thread.sleep(250); } catch (Exception e) { // since we are changing the arraylist for the adapter in the background, we need to make sure it // gets updated before continuing } query = result.nextQuery(); if (query != null) result = twitter.search(query); } while (query != null); } catch (Exception e) { e.printStackTrace(); } catch (OutOfMemoryError e) { e.printStackTrace(); } if (replies.size() < 2) { // nothing to show, so tell them that ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { progressBar.setVisibility(View.GONE); listView.setVisibility(View.GONE); none.setVisibility(View.VISIBLE); } }); } } }); getReplies.setPriority(8); getReplies.start(); }
From source file:com.klinker.android.twitter.adapters.PicturesArrayAdapter.java
License:Apache License
public void bindView(final View view, Context mContext, final String url, final Status status) { final ViewHolder holder = (ViewHolder) view.getTag(); Log.v("talon_picture", "text: " + status.getText()); Status thisStatus;//w w w . ja v a2s . co m String retweeter; final long time = status.getCreatedAt().getTime(); long originalTime = 0; if (status.isRetweet()) { retweeter = status.getUser().getScreenName(); thisStatus = status.getRetweetedStatus(); originalTime = thisStatus.getCreatedAt().getTime(); } else { retweeter = ""; thisStatus = status; } final String fRetweeter = retweeter; final long fOriginalTime = originalTime; User user = thisStatus.getUser(); final long id = thisStatus.getId(); final String profilePic = user.getBiggerProfileImageURL(); String tweetTexts = thisStatus.getText(); final String name = user.getName(); final String screenname = user.getScreenName(); String[] html = TweetLinkUtils.getLinksInStatus(thisStatus); final String tweetText = html[0]; final String picUrl = html[1]; final String otherUrl = html[2]; final String hashtags = html[3]; final String users = html[4]; holder.url = url; holder.iv.loadImage(url, false, new NetworkedCacheableImageView.OnImageLoadedListener() { @Override public void onImageLoaded(CacheableBitmapDrawable result) { holder.iv.setBackgroundDrawable(null); } }); holder.iv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String link; boolean displayPic = !picUrl.equals(""); if (displayPic) { link = picUrl; } else { link = otherUrl.split(" ")[0]; } Log.v("tweet_page", "clicked"); Intent viewTweet = new Intent(context, TweetPager.class); viewTweet.putExtra("name", name); viewTweet.putExtra("screenname", screenname); viewTweet.putExtra("time", time); viewTweet.putExtra("tweet", tweetText); viewTweet.putExtra("retweeter", fRetweeter); viewTweet.putExtra("webpage", link); viewTweet.putExtra("other_links", otherUrl); viewTweet.putExtra("picture", displayPic); viewTweet.putExtra("tweetid", id); viewTweet.putExtra("proPic", profilePic); viewTweet.putExtra("users", users); viewTweet.putExtra("hashtags", hashtags); context.startActivity(viewTweet); } }); }