1

我正在使用 twitter4j 代码,并且每天进行大约 5 次查询时连接超时。

我正在使用带有 servlet 的 twitter4j,并且由于超时而出现很多错误。

发生的事情是我运行代码并且系统在搜索时提供错误,因此系统停止并且没有提供更多详细信息。

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

    Twitter twitter = tf.getInstance();
      try {
       Query query = new Query(searchTerm);
       twitter4j.QueryResult result1;
       do {
           result1 = twitter.search(query);
           List<Status> tweets = result1.getTweets();
           int i=0;int maxint = 20;
           for (Status tweet : tweets) {
               i++;
               if (i<maxint)
               {
                  out.println("procvess");

               xmlStr=xmlStr+"<tweet>";
               String tweetText = tweet.getText();

                 tweetText=cleanStringData(tweetText );
HashtagEntity[] hashtags =  tweet.getHashtagEntities();
               URLEntity[] urls = tweet.getURLEntities(); 
               Date createdDate = tweet.getCreatedAt();
               User twitteruser = tweet.getUser();
               long tweetId = tweet.getId();
               long id1 = tweet.getInReplyToStatusId();
               long id2 = tweet.getInReplyToUserId(); 
   String userImageURL = twitteruser.getProfileImageURL();

        String userProfileURL =      "http://twitter.com/"+twitteruser.getScreenName();

               String realname = twitteruser.getName();
               String authorname = twitteruser.getScreenName();

                  Calendar cal = Calendar.getInstance();
                  cal.setTime(createdDate);
                  int year = cal.get(Calendar.YEAR);
                  int month = cal.get(Calendar.MONTH);
                  int day = cal.get(Calendar.DAY_OF_MONTH);

            String tweetDateStr =     String.valueOf(year)+"/"+String.valueOf(month)+"/"+String.valueOf(day);






               int l=0;






               xmlStr=xmlStr+"</tweet>";
               }
             //  System.out.println("@" + tweet.getUser().getScreenName() + " - " + tweet.getText());
           }
       } while ((query = result1.nextQuery()) != null);

   } catch (TwitterException te) {
       te.printStackTrace();

        out.println("Failed to search tweets: " + te.getMessage());
    //  return "<error>" + te.getMessage()+"</error>";

   }
4

0 回答 0