Getting SocketTimeoutException while retrieving twitter feeds


#1

Hi,

I have developed a small twitter feed retrieveal example using twitter4j but when I exceute code I am getting SockettimeoutException. Can someone please tell me why am I getting this exception and how to fix this issue ?

Below is exception I am getting,

TwitterException{exceptionCode=[f3acd3ed-00581fb2 2cf3e148-0aabd23d], statusCode=-1, retryAfter=0, rateLimitStatus=null, version=2.1.5-SNAPSHOT(build: d372a51b9b419cbd73d416474f4a855f3e889507)}
at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:323)
at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:72)
at twitter4j.internal.http.HttpClientWrapper.get(HttpClientWrapper.java:86)
at twitter4j.Twitter.search(Twitter.java:191)
at SearchTweets.main(SearchTweets.java:28)
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.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.(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.(HttpResponseImpl.java:42)
at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:286)
… 4 more
Failed to search tweets: connect timed out

Below is my sample code,

import java.util.List;

import twitter4j.Query;
import twitter4j.QueryResult;
import twitter4j.Tweet;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.conf.ConfigurationBuilder;

public class SearchTweets {

public static void main(String[] args) {
	
	ConfigurationBuilder cb = new ConfigurationBuilder();
	cb.setDebugEnabled(true);
	cb.setOAuthConsumerKey("*****************************");
	cb.setOAuthConsumerSecret("*************************");
	cb.setOAuthAccessToken("****************************");
	cb.setOAuthAccessTokenSecret("*********************");
	TwitterFactory tf = new TwitterFactory(cb.build());
	Twitter twitter = tf.getInstance();

	try {
		Query query = new Query("twitterapi"); // twitter user account
		query.setSince("2013-09-01");
					
		QueryResult result;
			result = twitter.search(query);
			List<Tweet> tweets = result.getTweets();
			for (Tweet tweet : tweets) {
				System.out.println(tweet.getFromUser() + " - " + tweet.getText());
			}
		System.exit(0);
	} catch (TwitterException te) {
		te.printStackTrace();
		System.out.println("Failed to search tweets: " + te.getMessage());
		System.exit(-1);
	}
}

}

Thanks in advance for your help.


#2