twitter4j错误 - 连接超时

时间:2013-07-27 12:05:12

标签: twitter4j

我正在使用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>";

   }

0 个答案:

没有答案