我正在运行此程序来搜索推文。粘贴以下异常。
任何人都可以帮助我解决问题吗?
如果需要任何其他详细信息,请告诉我。
由于
public class KrishsSearchTweets {
public static void main(String[] args) {
try {
Twitter twitter = new TwitterFactory().getInstance();
// My Applications Consumer and Auth Access Token
twitter.setOAuthConsumer("key", "secret");
twitter.setOAuthAccessToken(new AccessToken("token", "secret"));
System.out.println("Search Program started");
Query query = new Query("source:twitter4j");
query.setSince("20120101");
Object result = twitter.search(query);
System.out.println("Search Program ended");
} catch (TwitterException te) {
te.printStackTrace();
System.out.println("Failed to get timeline: " + te.getMessage());
}
}
}
例外:
Search Program started
connect timed out
Relevant discussions can be found on the Internet at:
http://www.google.co.jp/search?q=d35baff5 or
http://www.google.co.jp/search?q=12c94143
TwitterException{exceptionCode=[d35baff5-12c94143 43208640-465ee2e3], statusCode=-1, message=null, code=-1, retryAfter=-1, rateLimitStatus=null, version=3.0.3}
at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:192)
at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:61)
at twitter4j.internal.http.HttpClientWrapper.get(HttpClientWrapper.java:81)
at twitter4j.TwitterImpl.get(TwitterImpl.java:1835)
at twitter4j.TwitterImpl.search(TwitterImpl.java:282)
at KrishsSearchTweets.main(KrishsSearchTweets.java:30)
Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.HttpURLConnection.getResponseCode(Unknown Source)
at twitter4j.internal.http.HttpResponseImpl.<init>(HttpResponseImpl.java:34)
at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:156)
Failed to get timeline: connect timed out
... 5 more
答案 0 :(得分:1)
问题得到解决。这是因为网络中的防火墙不允许连接和超时。
我删除防火墙后就可以了。