2013-05-17 3 views
1

나는이 라이브러리에서 나를 훈련시키기 위해 twitter4j의 기본 기능을 작동 시키려고합니다. 내 첫 번째 테스트는 내 타임 라인을 검색하는 것입니다 사이트 twitter4j에 대한 첫 번째 튜토리얼 중 하나입니다.Twitter4j, 알 수없는 호스트 예외

여기 내 타임 라인을 검색하려면 코드는 다음과 같습니다

String accessToken = "***"; 
String accessSecret = "***"; 
String consumerKey = "***"; 
String consumerSecret = "***"; 

ConfigurationBuilder cb = new ConfigurationBuilder(); 
cb.setDebugEnabled(true) 
    .setOAuthConsumerKey(consumerKey) 
    .setOAuthConsumerSecret(consumerSecret) 
    .setOAuthAccessToken(accessToken) 
    .setOAuthAccessTokenSecret(accessSecret); 

TwitterFactory tf = new TwitterFactory(cb.build()); 
Twitter twitter = tf.getInstance(); 

List<Status> statuses = twitter.getHomeTimeline(); 

System.out.println("Showing home timeline."); 

for (Status status : statuses) { 

    System.out.println(status.getUser().getName() + ":" + 
    status.getText()); 

} 

그러나이 간단한 코드

, 나는 다음과 같은 오류가 있습니다

Exception in thread "main" api.twitter.com 
Relevant discussions can be found on the Internet at: 
    http://www.google.co.jp/search?q=e5488403 or 
    http://www.google.co.jp/search?q=09b41b1e 
TwitterException{exceptionCode=[e5488403-09b41b1e 6ece33f2-2ccf4468], 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.getHomeTimeline(TwitterImpl.java:117) 
    at Test.main(Test.java:32) 
Caused by: java.net.UnknownHostException: api.twitter.com 
    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) 
    ... 5 more 

문제가 있습니까?

답변

0

마지막으로, 내 문제가있어, 코드는 완벽했지만 프록시가 있습니다. 그래서 그것을 고쳤습니다 :

ConfigurationBuilder cb = new ConfigurationBuilder(); 
    cb.setDebugEnabled(true) 
      .setOAuthConsumerKey(consumerKey) 
      .setOAuthConsumerSecret(consumerSecret) 
      .setOAuthAccessToken(accessToken) 
      .setOAuthAccessTokenSecret(accessSecret) 

      // PROXY 
      .setHttpProxyHost(proxyHost) 
      .setHttpProxyPort(proxyPort) 
      ;