1
我想使用谷歌定製搜索API的Java,但在某些原因,它不工作。這是我的Java代碼:谷歌定製搜索API的Java
String searchText = "football";
String key="mykey";
String cx = "mygeneratedcx";
HttpRequestInitializer httpRequestInitializer = new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest request) throws IOException {
}
};
JsonFactory jsonFactory = new JacksonFactory();
Customsearch custom = new Customsearch(new NetHttpTransport(), jsonFactory, httpRequestInitializer);
Customsearch.Cse.List list = custom.cse().list("football");
list.setCx(cx);
list.setKey(key);
Search result = list.execute();
List listResult = (List) result.getItems();
Result first = (Result) listResult.get(0);
而且thease是我的依賴使用API:
<dependency>
<groupId>com.google.api.client</groupId>
<artifactId>google-api-client-http</artifactId>
<version>1.2.3-alpha</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-customsearch</artifactId>
<version>v1-rev30-1.17.0-rc</version>
</dependency>
我已經看到了一些例子,但它們不是根據API的thease版本,我得到。 當上述代碼執行我接收到以下情況例外:在螺紋
異常 「主」 java.lang.NoSuchMethodError:com.google.api.client.util.Strings.isNullOrEmpty(Ljava /郎/字符串;)z 在com.google.api.client.googleapis.services.AbstractGoogleClient
如果有人已經使用的Java這個谷歌定製搜索API,我會幫忙非常感謝!
預先感謝您!