I'm very new to twitter API (using Twitter4j) to read my tweets. I have set up my app with the twitter and got the KEY,SECRET and TOKEN/TOKENSECRET
Below is the code which I have written.
public final class ReadTweets {
public static void main(String[] args) {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("myKEY")
.setOAuthConsumerSecret("mySECRET")
.setOAuthAccessToken("myTOKEN")
.setOAuthAccessTokenSecret("myTOKENSECRET");
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
try {
ResponseList<Status> a = twitter.getUserTimeline(new Paging(1,5));
for(Status b :a){
System.out.println(b.getText());
}
} catch (TwitterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
But Im getting the following error.
api.twitter.com
Relevant discussions can be found on the Internet at:
http://www.google.co.jp/search?q=4be80492 or
http://www.google.co.jp/search?q=0bf5b837
TwitterException{exceptionCode=[4be80492-0bf5b837 d7e149ce-72c14a70], statusCode=-1, message=null, code=-1, retryAfter=-1, rateLimitStatus=null, version=4.0.2}
at twitter4j.HttpClientImpl.handleRequest(HttpClientImpl.java:178)
at twitter4j.HttpClientBase.request(HttpClientBase.java:53)
at twitter4j.HttpClientBase.get(HttpClientBase.java:71)
at twitter4j.TwitterImpl.get(TwitterImpl.java:1556)
at twitter4j.TwitterImpl.getUserTimeline(TwitterImpl.java:167)
at com.test.twitter.UpdateStatus.main(UpdateStatus.java:47)
Caused by: java.net.UnknownHostException: api.twitter.com
at java.net.AbstractPlainSocketImpl.connect(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.security.ssl.SSLSocketImpl.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.protocol.https.HttpsClient.<init>(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.New(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.HttpURLConnection.getResponseCode(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(Unknown Source)
at twitter4j.HttpResponseImpl.<init>(HttpResponseImpl.java:35)
at twitter4j.HttpClientImpl.handleRequest(HttpClientImpl.java:142)
... 5 more
Though I added a proxy to my Configuration Builder code and it worked.
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("myKEY")
.setOAuthConsumerSecret("MySecret")
.setOAuthAccessToken("Token")
.setOAuthAccessTokenSecret("TokenSecret")
.setHttpProxyHost("ProxyServer")
.setHttpProxyPort(Port);
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
My question is why do I have to use a proxy to get my code working. Is there any other way around ?