2015-09-26 16 views
0

基本上,我試圖編碼和運行以下雅虎查詢使用Java。我已經在這個網站有多個線程。但是,我仍然沒有得到正確的答案。無法編碼和運行Java中的雅虎查詢

String url = "https://query.yahooapis.com/v1/public/yql?"; 
    String yql_query = "select * from yahoo.finance.quotes where symbol=\"0001.hk\""; 
    String yql_query1 = yql_query.replace(" ", "%20"); 
    String fullUrl = url + URLEncoder.encode(yql_query1, "UTF-8") + "&format=json"; 
    System.out.println(fullUrl); 
    Document doc = Jsoup.connect(fullUrl).get(); 

結果查詢看起來像這樣在控制檯:

https://query.yahooapis.com/v1/public/yql?select%2520*%2520from%2520yahoo.finance.quotes%2520where%2520symbol%3D%220001.hk%22&format=json 

現在,我完全陌生的API的這個概念。我想知道在運行上面的代碼之前,我是否需要設置OAuth?我如何獲得上面的代碼工作?

+0

前加,你會得到下面的錯誤: '{「error」:{「lang」:「en-US」,「description」:「你必須指定一個yql語句(q =)來執行」}}'... –

+0

是的,我知道,但我不知道如何解決它。 – mynameisJEFF

+0

檢查我的答案,然後 –

回答

0

如果你在瀏覽器中運行查詢,你會得到下面的錯誤:如果您在瀏覽器中運行查詢

{"error":{"lang":"en-US","description":"You must specify a yql statement (q=) to execute"}}

所以「Q =」只選擇

String yql_query = "q=" + "select * from yahoo.finance.quotes where symbol=\"0001.hk\"";