0
當我嘗試使用谷歌自定義搜索API時,我得到了錯誤。 在服務器Google中,我可以看到我的請求。自定義搜索API
代碼:
public class Main {
private static final String APPLICATION_NAME = "MyWeb";
private static final String API_KEY = "00000";
private static final String engine = ("000000");
private static HttpTransport httpTransport;
@SuppressWarnings("unused")
private static Customsearch client;
public static void main(String[] args) throws IOException {
Customsearch customsearch = new Customsearch(new NetHttpTransport(), new JacksonFactory(),null);
try {
Customsearch.Cse.List list = customsearch.cse().list("HERE");
list.setKey(API_KEY);
list.setCx(engine);
Search results = list.execute();
List<Result> items = results.getItems();
for(Result result:items)
{
System.out.println("Title:"+result.getHtmlTitle());
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
錯誤:
Exception in thread "main" java.lang.AbstractMethodError: com.google.api.client.json.JsonFactory.createJsonParser(Ljava/io/InputStream;Ljava/nio/charset/Charset;)Lcom/google/api/client/json/JsonParser;
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:85)
at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:81)
at com.google.api.client.http.HttpResponse.parseAs(HttpResponse.java:459)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)
at com.korney.Main.main(Main.java:44)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Process finished with exit code 1
你在類路徑上有一個API,你是否也有一個實現?如果這不是問題,請發佈一些代碼請... – Caleryn
你用戶'JsonFactory'類 – lakshman