Bing搜索api与java

时间:2014-09-10 13:17:02

标签: java api search bing

使用bing api和java(不是android)

hava这段代码:

import java.util.Iterator;

import net.billylieurance.azuresearch.AbstractAzureSearchQuery.AZURESEARCH_FORMAT;
import net.billylieurance.azuresearch.AzureSearchResultSet;
import net.billylieurance.azuresearch.AzureSearchWebQuery;
import net.billylieurance.azuresearch.AzureSearchWebResult;


public class mainTest {

    public static void main(String[] args){

        AzureSearchWebQuery aq = new AzureSearchWebQuery();

        String ACCOUNT_KEY = "WgQGPMPJH0FKBc/aWdiAeb05PiChO5XToKfDSmZ/Xuo";
        aq.setAppid(ACCOUNT_KEY);

        aq.setFormat(AZURESEARCH_FORMAT.XML);

        // searchParam is the field containing the keyword to be searched.
        aq.setQuery("games");

        aq.doQuery();

        AzureSearchResultSet<AzureSearchWebResult> azureSearchResultSet = aq
        .getQueryResult();

        for (Iterator<AzureSearchWebResult> iterator = azureSearchResultSet
        .iterator(); iterator.hasNext();) {
        AzureSearchWebResult result = (AzureSearchWebResult) iterator
        .next();

        // Populate the data from result object in to your custom objects.

        System.out.println(result.getTitle());
        System.out.println(result.getUrl());
        System.out.println(result.getDisplayUrl());
        System.out.println(result.getDescription());


        }




    }

也是我的罐子:

apache-httpcomponents-httpcore
azure-bing-search-java-0.12.0
httpclient-4.2.3
org-apache-commons-logging

但得到了错误:

Exception in thread "main" java.lang.NoSuchFieldError: DEF_CONTENT_CHARSET
  at org.apache.http.impl.client.DefaultHttpClient.setDefaultHttpParams(DefaultHttpClient.java:175)
  at org.apache.http.impl.client.DefaultHttpClient.createHttpParams(DefaultHttpClient.java:158)
  at org.apache.http.impl.client.AbstractHttpClient.getParams(AbstractHttpClient.java:448)
  at org.apache.http.impl.client.AbstractHttpClient.createClientConnectionManager(AbstractHttpClient.java:309)
  at org.apache.http.impl.client.AbstractHttpClient.getConnectionManager(AbstractHttpClient.java:466)
  at org.apache.http.impl.client.AbstractHttpClient.createHttpContext(AbstractHttpClient.java:286)
  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:851)
  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:805)
  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:784)
  at net.billylieurance.azuresearch.AbstractAzureSearchQuery.doQuery(AbstractAzureSearchQuery.java:338)
  at mainTest.main(mainTest.java:38)
我读了一些可能是罐子彼此不兼容的地方。但是dot知道怎么检查。或者别的什么的。

任何建议都会有所帮助。

1 个答案:

答案 0 :(得分:0)

您的类路径中有两个或多个httpcore jars。