我創建了這個簡單的類:安裝Unirest Java的消耗Mashape API
import javax.swing.JOptionPane;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
public class TweetSent {
public static void main(String[] args) {
try {
HttpResponse<JsonNode> request = Unirest.get("https://intridea-tweetsentiments.p.mashape.com/twitsentiment/?num_tweets=10&query=%3Cquery%3E").basicAuth("X-Mashape-Authorization", "#######################").asJson();
JOptionPane.showMessageDialog(null,"request: "+request);
} catch (UnirestException e) {
JOptionPane.showMessageDialog(null,"ERROR: "+e);
e.printStackTrace();
}
}
}
但我得到這個錯誤:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/codec/binary/Base64
at com.mashape.unirest.request.HttpRequest.basicAuth(HttpRequest.java:61)
at com.NR.V.TweetSent.main(TweetSent.java:21)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.codec.binary.Base64
編輯:
我刪除了所有的在pom.xml
文件中提到的<repository>
元素:
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>1.3.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
<version>4.0-beta4</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.3</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>
我得到這個從Maven的:
[WARNING] The POM for com.mashape.unirest:unirest-java:jar:1.3.0-SNAPSHOT is missing, no dependency information available
Maven說它找不到工件1.3.0-SNAPSHOT,但它可以找到1.2.8 – ManInMoon
Unirest現在使用Maven Central。嘗試刪除條目。正如你所看到的,它已經正確上傳:https://oss.sonatype.org/content/repositories/snapshots/com/mashape/unirest/unirest-java/1.3.0-SNAPSHOT/ –
Mark
仍然沒有運氣。請參閱有關EDIT 2的問題。 – ManInMoon