Twitter4j - reply to tweet
in
Contributed Library Questions
•
3 months ago
Hi,
Has anybody any ideas on how to reply to a tweet using Twitter4j?
I want to be able for search for tweets, and when I find these tweets, I want to be able to reply to a particular tweet.
Say I'm searching for tweets with the work 'ProcessingForum'. I search for these tweets, and get the ScreenName by using getScreenName();. I can send tweets to anybody who has tweeted something with the string 'ProcessingForum', but I want to be able to
reply to the particular tweet that has mentioned 'ProcessingFroum'.
Any Ideas?
Some code below that shows how I'm doing it so far
- String sendto = ""; ///////string to store the ScreenName
- void setup() {
- size(100,100);
- background(0);
- connectTwitter();
- getTimeline(); //gets tweets from my timeline
- getSearchTweets(); //gets any tweets with the defined string ///get the screen name before I send the tweet\\\\\
- sendTweet("@"+ sendto + " You just tweeted about arsejesustweeting, you pup! (attempt #5)");
- }
- void getSearchTweets() { //search for all tweets
- String queryStr = "ProcessingForum";
- try {
- Query query = new Query(queryStr);
- query.count(10); // Get 10 of the 100 search results
- QueryResult result = twitter.search(query);
- ArrayList tweets = (ArrayList) result.getTweets();
- for (int i=0; i<tweets.size(); i++) {
- //Tweet t = (Tweet)tweets.get(i);
- //String user = t.getFromUser();
- //String msg = t.getText();
- Status t=(Status) tweets.get(i);
- User u=(User) t.getUser();
- String user=u.getName();
- String scrName=u.getScreenName(); //////////gets the screen name\\\\\\\\\\\
- long id=u.getId();
- String msg = t.getText();
- String rply = t.getInReplyToScreenName();
- Date d = t.getCreatedAt();
- theSearchTweets[i] = msg.substring(queryStr.length()+1);
- println("Tweet by " + scrName + " at " + d + ": " + msg);
- println(theSearchTweets[i]);
- println("In reply to this Screen Name" + rply);
- sendto = scrName;
- }
- } catch (TwitterException e) {
- println("Search tweets: " + e);
- }
- }
1