Twitter Connection TimeOUT

twitter4j
java

#1

I am new to twiiter4J and I am getting this exception , I have tried different ways like increasing timeout time and disabling windows firewall but nothing

connect timed out
Relevant discussions can be found on the Internet at:
	http://www.google.co.jp/search?q=ec1fe56d or
	http://www.google.co.jp/search?q=200cd646
TwitterException{exceptionCode=[ec1fe56d-200cd646 3ea58453-e18dee41], statusCode=-1, message=null, code=-1, retryAfter=-1, rateLimitStatus=null, version=4.0.4}
	at twitter4j.HttpClientImpl.handleRequest(HttpClientImpl.java:179)
	at twitter4j.HttpClientBase.request(HttpClientBase.java:57)
	at twitter4j.HttpClientBase.get(HttpClientBase.java:75)
	at twitter4j.TwitterBaseImpl.fillInIDAndScreenName(TwitterBaseImpl.java:129)
	at twitter4j.TwitterImpl.verifyCredentials(TwitterImpl.java:578)
	at NewClass.main(NewClass.java:46)
Caused by: java.net.SocketTimeoutException: connect timed out
	at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
	at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
	at java.net.Socket.connect(Socket.java:589)
	at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)
	at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
	at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
	at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
	at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264)
	at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)
	at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
	at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1138)
	at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1032)
	at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1546)
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
	at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
	at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338)
	at twitter4j.HttpResponseImpl.<init>(HttpResponseImpl.java:35)
	at twitter4j.HttpClientImpl.handleRequest(HttpClientImpl.java:143)
	... 5 more

and here is my code

import twitter4j.Status;
import twitter4j.Twitter;
import twitter4j.TwitterFactory;

import twitter4j.conf.ConfigurationBuilder;

/**
 *
 * @author Kashif
 */
public class NewClass {
    public static void main(String arg[]){
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true);
    cb.setOAuthConsumerKey("sVxxxxxxxUvdV");
    cb.setOAuthConsumerSecret("nRxxxxxxxXwY7i");
    cb.setOAuthAccessToken("71xxxxxxxZDuA7");
    cb.setOAuthAccessTokenSecret("Yzxxxxxx0Y7clyc");
            
  

    try {
 
            Twitter twitter = new TwitterFactory(cb.build()).getInstance();
 
            twitter.verifyCredentials();
 
             Status status = twitter.updateStatus("This is my ");

        } catch (Exception e) {

              e.printStackTrace();

        }

       }
}

#2

First of all, please do not post your OAuth tokens in a public forum post - doing so enables anyone to steal your account identity and post on your behalf via your app, so this is a really bad idea. I edited them out for you.

Secondly - the error seems to happen here:

java.net.SocketTimeoutException: connect timed out

Are you able to connect to api.twitter.com from your host? What is the network latency? That’s a fairly standard Java networking error, not directly related to using Twitter functions. I’d start checking from there.


#3

Thanks a lot for your reply . I have checked the speed download speed is 30 Mb/s and upload is 20 Mb/s . If it is a network problem how can I resolve this ? As I am in China , I already using Psiphon VPN , do I need to edit some settings , Please guide


#4

I also want to clarify that this line work fine Twitter twitter = new TwitterFactory(cb.build()).getInstance();

But exception raises when this line verifyCredentials executed
twitter.verifyCredentials();


#5

I resolve this issue by adding proxy server info in my code . Thanks @andypiper for your hint


#6

Glad to hear you figured it out! :thumbsup:


#7