2014-01-20 43 views
0

首先,我很抱歉我的英語。 我正在開發Java編寫的應用程序,我想使用搜索必應API,所以,我打開冰(http://www.bing.com/dev/en-us/dev-center)的用戶爲中心的發展和接受的關鍵號碼,然後我寫了下面的代碼,得到的結果兵Bing API錯誤1002

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"}] 
}} 
+0

下一次粘貼數據時,儘量使代碼和其他片段** **可讀;) – quetzalcoatl

+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

+0

首先感謝您的快速回復 我解決了Appid = MyClientId =女孩的問題,但它仍然不起作用 我閱讀了文檔,但我無法弄清楚我在哪裏把關鍵字放在url地址中 再次感謝幫助 – user2320349