Bing API错误1002

时间:2014-01-20 09:21:05

标签: java

首先,我很抱歉我的英语。 我正在用java开发一个应用程序,我想使用搜索Bing API,所以我打开了Bing(http://www.bing.com/dev/en-us/dev-center)的用户中心开发并接受了密钥号,然后我编写了以下代码来获得结果Bing

String q = "http://api.bing.net/json.aspx?Appid=MyClientId=girls&sources=web&web.count=40&web.offset=41";

URL searchURL;
try {
    searchURL = new URL(q);
    HttpURLConnection httpURLConnection = (HttpURLConnection) searchURL.openConnection();

    if(httpURLConnection.getResponseCode() == HttpURLConnection.HTTP_OK){
        InputStreamReader inputStreamReader = new InputStreamReader(httpURLConnection.getInputStream());
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader, 8192);

        String line = null;
        String result = "";
        while((line = bufferedReader.readLine()) != null){
            result += line;
        }

        bufferedReader.close();
    }
} catch (MalformedURLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

为什么我会收到以下错误1002?

{"SearchResponse":{
    "Version":"2.2",
    "Query":{"SearchTerms":"girls"},
    "Errors":[
        {"Code":1002,
         "Message":"Parameter has invalid value.",
         "Parameter":"SearchRequest.AppId",
         "Value":"MyClientId",
         "HelpUrl":"http:\/\/msdn.microsoft.com\/en-us\/library\/dd251042.aspx"}]
}}

1 个答案:

答案 0 :(得分:1)

看起来你的地址上有一个拼写错误 这看起来很可疑:

Appid=MyClientId=girls

您应该看到文档http://msdn.microsoft.com/en-us/library/dd250882.aspx,但我想您需要用某些内容替换MyClientId,并且您还没有将查询和clientId替换为&q=girls

编辑:您需要将AppId移到某处Steps of creating appid for bing search

以下是一些可以帮助您的问题: Bing search API and Azure