我試圖通過oauth訪問Twitter。因此,我註冊了我的應用程序,下載Twitter4j,我在Eclipse的項目加入罐,然後試圖執行以下代碼:Twitter4J在TwitterFactory中拋出異常
Twitter twitter = new TwitterFactory().getOAuthAuthorizedInstance("[key]","[secretKey]");
RequestToken requestToken = twitter.getOAuthRequestToken();
System.out.println(requestToken.getAuthorizationURL());
但它會引發以下異常:
[Sat May 29 11:19:11 CEST 2010]Using class twitter4j.internal.logging.StdOutLoggerFactory as logging factory.
[Sat May 29 11:19:11 CEST 2010]Use twitter4j.internal.http.alternative.HttpClientImpl as HttpClient implementation.
Exception in thread "main" java.lang.AssertionError: java.lang.reflect.InvocationTargetException
at twitter4j.internal.http.HttpClientFactory.getInstance(HttpClientFactory.java:71)
at twitter4j.internal.http.HttpClientWrapper.<init>(HttpClientWrapper.java:59)
at twitter4j.http.OAuthAuthorization.init(OAuthAuthorization.java:83)
at twitter4j.http.OAuthAuthorization.<init>(OAuthAuthorization.java:74)
at twitter4j.TwitterFactory.getOAuthAuthorizedInstance(TwitterFactory.java:112)
at MainProgram.main(MainProgram.java:18)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at twitter4j.internal.http.HttpClientFactory.getInstance(HttpClientFactory.java:65)
... 5 more
Caused by: java.lang.NoClassDefFoundError: org/apache/http/impl/client/DefaultHttpClient
at twitter4j.internal.http.alternative.HttpClientImpl.<init>(HttpClientImpl.java:63)
... 10 more
我目前無法弄清楚爲什麼...你能給我一些建議嗎?
問候 菲利普
我已經添加了twitter4j-httpclient-support-2.1.3-SNAPSHOT.jar以及httpclient-4.0.1.jar,但是這並沒有改變任何東西。 :/ – 2010-05-29 09:39:12
嘗試在一個簡單的類中使用DefaultHttpClient以確保它實際上位於項目的類路徑中 – Guillaume 2010-05-29 09:52:14
DefaultHttpClient client = new DefaultHttpClient();無任何例外地執行。 – 2010-05-29 10:05:15