twitter4j.Twitter.search()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(148)

本文整理了Java中twitter4j.Twitter.search()方法的一些代码示例,展示了Twitter.search()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Twitter.search()方法的具体详情如下:
包路径:twitter4j.Twitter
类名称:Twitter
方法名:search

Twitter.search介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

query.setCount(numberOfTweets - tweets.size());
try {
 QueryResult result = twitter.search(query);
 tweets.addAll(result.getTweets());
 println("Gathered " + tweets.size() + " tweets");

代码示例来源:origin: stackoverflow.com

@Override
protected ArrayList<String> doInBackground(String... arg0) {

  List<twitter4j.Status> tweets = new ArrayList();
  tweetTexts.clear();

  Twitter mTwitter = getTwitter();
  try {

    tweets = mTwitter.search(new Query(searchText)).getTweets();
    for (twitter4j.Status t : tweets) {
    tweetTexts.add(t.getText() + "\n\n");
    }

  } catch (Exception e) {
    Log.e("Error", "Exception");
  }


  return tweetTexts;
}

代码示例来源:origin: org.twitter4j/twitter4j-async

@Override
  public void invoke(List<TwitterListener> listeners) throws TwitterException {
    QueryResult result = twitter.search(query);
    for (TwitterListener listener : listeners) {
      try {
        listener.searched(result);
      } catch (Exception e) {
        logger.warn("Exception at search", e);
      }
    }
  }
});

代码示例来源:origin: stackoverflow.com

Query query = new Query("from:somebody").since("2011-01-02");
Twitter twitter = new TwitterFactory().getInstance();
QueryResult result = twitter.search(query);

代码示例来源:origin: stackoverflow.com

Twitter twitter = TwitterFactory.getSingleton();
Query query = new Query("source:twitter4j yusukey");
QueryResult result = twitter.search(query);
for (Status status : result.getStatuses()) {
  System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText());
}

代码示例来源:origin: stackoverflow.com

Twitter twitter = TwitterFactory.getSingleton();
Query query = new Query("source:twitter4j yusukey");
QueryResult result = twitter.search(query);
for (Status status : result.getStatuses()) {
  System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText());
}

代码示例来源:origin: stackoverflow.com

Twitter twitter = new TwitterFactory().getInstance();
try {
  QueryResult result = twitter.search(new Query("#myhashtag"));
} catch (TwitterException te) {
  te.printStackTrace();
}

代码示例来源:origin: stackoverflow.com

Twitter twitter = new TwitterFactory().getInstance();
Query query = new Query("lizardbill");
QueryResult result = twitter.search(query);

for (Tweet tweet : result.getTweets()) {
  System.out.println(tweet.getFromUser() + ":" + tweet.getText());
  for (URLEntity urle : tweet.getURLEntities()) {
    System.out.println(urle.getDisplayURL());
  }
}

代码示例来源:origin: borax12/Searcher

@Override
protected List<twitter4j.Status> doInBackground(String... params) {
  Twitter twitter = TwitterWrapper.getTwitterInstance(context.getApplicationContext());
  List<twitter4j.Status> tweets = null;
  try {
    Query query = new Query(params[0]);
    QueryResult result;
    result = twitter.search(query);
    tweets = result.getTweets();
  } catch (TwitterException te) {
    te.printStackTrace();
    System.out.println("Failed to search tweets: " + te.getMessage());
  }
  return tweets;
}

代码示例来源:origin: stackoverflow.com

Twitter twitter = TwitterFactory.getSingleton();
Query query = new Query("...");
QueryResult result = twitter.search(query);
for (Status status : result.getTweets()) {
  for (MediaEntity mediaEntity : status.getMediaEntities()) {
    System.out.println(mediaEntity.getType() + ": " + mediaEntity.getMediaURL());
  }
}

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) throws TwitterException { 
 Twitter twitter = new TwitterFactory().getInstance();
 Query query = new Query("**your query**");
 query.setRpp(100); // here you show 100 tweets
 QueryResult result = twitter.search(query);
 for (Tweet tweet : result.getTweets()) {
  System.out.println(tweet.getFromUser() + ":" + tweet.getText());
 }
}

代码示例来源:origin: stackoverflow.com

ConfigurationBuilder cb = new ConfigurationBuilder();
           cb.setDebugEnabled(true)
               .setOAuthConsumerKey("your key")
               .setOAuthConsumerSecret(
                   "your key")
               .setOAuthAccessToken(
                   "your key")
               .setOAuthAccessTokenSecret(
                   "your key");
           TwitterFactory tf = new TwitterFactory(cb.build());
           Twitter twitter = tf.getInstance();
             Query query = new Query("#iphone7");
             query.setCount(100);
             try {
               result = twitter.search(query);
               tweets.addAll(result.getTweets());
               System.out.println("Gathered " + tweets.size() + " tweets");
           } catch (TwitterException te) {
               System.out.println("Couldn't connect: " + te.toString());
           }

代码示例来源:origin: stackoverflow.com

Twitter twitter = new TwitterFactory().getInstance();
     AccessToken accessToken = new AccessToken(accessTokenStr, accessTokenSecretStr);
     twitter.setOAuthConsumer(consumerKeyStr, consumerSecretStr);
     twitter.setOAuthAccessToken(accessToken);
     try {
       Query query = new Query("#<HASHTAG TO SEARCH>");
       QueryResult result;
       result = twitter.search(query);
       List<Status> tweets = result.getTweets();
       for (Status tweet : tweets) {
         System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getText());
       }
     }
     catch (TwitterException te) {
       te.printStackTrace();
       System.out.println("Failed to search tweets: " + te.getMessage());
       System.exit(-1);
     }

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) throws TwitterException {
  Twitter twitter = new TwitterFactory().getInstance();

  for (int page = 1; page <= 10; page++) {
    System.out.println("\nPage: " + page);
    Query query = new Query("#MyWorstFear"); // trending right now
    query.setRpp(100);
    query.setPage(page);
    QueryResult qr = twitter.search(query);
    List<Tweet> qrTweets = qr.getTweets();

    if(qrTweets.size() == 0) break;

    for(Tweet t : qrTweets) {
      System.out.println(t.getId() + " - " + t.getCreatedAt() + ": " + t.getText());
    }
  }
}

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) throws TwitterException {
  Twitter twitter = new TwitterFactory().getInstance();

  for (int page = 1; page <= 10; page++) {
    System.out.println("\nPage: " + page);
    Query query = new Query("#iPhone5");
    query.setRpp(100); // set tweets per page to 100
    query.setPage(page);
    QueryResult qr = twitter.search(query);
    List<Tweet> qrTweets = qr.getTweets();

    // break out of the loop early if there are no more tweets
    if(qrTweets.size() == 0) break;

    for(Tweet t : qrTweets) {
      System.out.println(t.getId() + " - " + t.getCreatedAt() + ": " + t.getText());
    }
  }
}

代码示例来源:origin: stackoverflow.com

private static final String TWITTER_CONSUMER_KEY = "xxxxxxxxxxxxxxxxxx";
private static final String TWITTER_SECRET_KEY = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
private static final String TWITTER_ACCESS_TOKEN = "xxxxxxxxxxxxxxxxxxxxxxx";
private static final String TWITTER_ACCESS_TOKEN_SECRET = "xxxxxxxxxxxxxxxxxxxxxxxxx";

ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
  .setOAuthConsumerKey(TWITTER_CONSUMER_KEY)
  .setOAuthConsumerSecret(TWITTER_SECRET_KEY)
  .setOAuthAccessToken(TWITTER_ACCESS_TOKEN)
  .setOAuthAccessTokenSecret(TWITTER_ACCESS_TOKEN_SECRET);
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
try {
  Query query = new Query("MrEdPanama");
  QueryResult result;
  do {
    result = twitter.search(query);
    List<Status> tweets = result.getTweets();
    for (Status tweet : tweets) {
      System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getText());
    }
  } while ((query = result.nextQuery()) != null);
  System.exit(0);
} catch (TwitterException te) {
  te.printStackTrace();
  System.out.println("Failed to search tweets: " + te.getMessage());
  System.exit(-1);
}

代码示例来源:origin: apache/asterixdb

@Override
public IRawRecord<char[]> next() throws IOException, InterruptedException {
  if (result == null || nextTweetIndex >= result.getTweets().size()) {
    Thread.sleep(1000 * requestInterval);
    query.setSinceId(lastTweetIdReceived);
    try {
      result = twitter.search(query);
    } catch (TwitterException e) {
      throw HyracksDataException.create(e);
    }
    nextTweetIndex = 0;
  }
  if (result != null && !result.getTweets().isEmpty()) {
    List<Status> tw = result.getTweets();
    Status tweet = tw.get(nextTweetIndex++);
    if (lastTweetIdReceived < tweet.getId()) {
      lastTweetIdReceived = tweet.getId();
    }
    String jsonTweet = TwitterObjectFactory.getRawJSON(tweet); // transform tweet obj to json
    record.set(jsonTweet);
    return record;
  } else {
    return null;
  }
}

代码示例来源:origin: stackoverflow.com

query.setRpp(100); // 100 results per page
query.setPage(page);
QueryResult qr = twitter.search(query);
List<Tweet> qrTweets = qr.getTweets();

代码示例来源:origin: stackoverflow.com

ConfigurationBuilder cb = new ConfigurationBuilder();
     cb.setDebugEnabled(true)
      .setOAuthConsumerKey("*******")
      .setOAuthConsumerSecret("****")
      .setOAuthAccessToken("*****")
      .setOAuthAccessTokenSecret("*****");
     TwitterFactory tf = new TwitterFactory(cb.build());
     final Twitter twitter = tf.getInstance();
     Query query = new Query("source:twitter4j yusukey");
     new Thread(new Runnable() { 
       @Override
       public void run() {
         try {
           QueryResult result = twitter.search(query);
           for (Status status : result.getTweets()) {
               System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText());
           }
         } catch (TwitterException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
         }
       }
     }).start();

代码示例来源:origin: stackoverflow.com

query.setLocale("en_IN");
query.setCount(100);
QueryResult result = twitter.search(query);
System.out.println("Output File "+ args[1]);
System.out.println(result.getTweets());

相关文章