I am using a twitter search api, and hoping to make it show tweet text results and no handle

port twitter4j.conf.*;
import twitter4j.*;
import twitter4j.auth.*;
import twitter4j.api.*;
import java.util.*;

Twitter twitter;
String searchString = "Rest In Peace";
List<Status> tweets;

int currentTweet;
int offsetx, offsety;
PFont f;
//PImage img;
void setup()
{

   f = loadFont("HelveticaNeue-Bold-90.vlw");


  size(displayWidth, displayHeight);




  // for twitter
  ConfigurationBuilder cb = new ConfigurationBuilder();
  cb.setOAuthConsumerKey("...");
  cb.setOAuthConsumerSecret("...");
  cb.setOAuthAccessToken("...");
  cb.setOAuthAccessTokenSecret("...");

  TwitterFactory tf = new TwitterFactory(cb.build());

  twitter = tf.getInstance();

  getNewTweets();

  currentTweet = 0;


}

void draw()
{
  background(255);
   textAlign (CENTER, TOP);
   textFont(f, 90);

  currentTweet = currentTweet + 1;

  if (currentTweet >= tweets.size())
  {
    print("getting new tweets");

    currentTweet = 0;
    getNewTweets();

  }
  Status status = tweets.get(currentTweet);

  fill(0);
text(status.getText(), 0, 200, displayWidth, displayHeight);

   delay(1000);
}

void getNewTweets()
{
  try
  {
      Query query = new Query(searchString);

      QueryResult result = twitter.search(query);

      tweets = result.getTweets();
  }
  catch (TwitterException te)
  {
      System.out.println("Failed to search tweets: " + te.getMessage());
      System.exit(-1);
  }

  //going to print out new tweets
  int curt = 0;
  for(int i=0; i< tweets.size(); i++){

   Status status = tweets.get(curt);
   print(status.getText() + "\n");
   curt = curt + 1;
  }
}

void refreshTweets()
{
  while (true)
  {
      getNewTweets();

      println("Updated Tweets");

      delay(30000);
  }
}

I would like to get and display the complete tweets with out the user handle and without an html code showing up right now it looks like this

Screenshot 2017-12-21 15.29.30

Screenshot 2017-12-21 15.29.31

Screenshot 2017-12-21 15.29.33

Screenshot 2017-12-21 15.29.34

Tagged:

Answers

  • I would like to get and display the complete tweets with out the user handle and without an html code

    Isn't that already what you're showing?

  • Don't post your Twitter credentials on a public message board.

Sign In or Register to comment.