2014-01-13 19 views
0

即時得到上試圖使用從谷歌API地圖的網絡服務出現以下錯誤:錯誤使用googmaps API

{ 「ERROR_MESSAGE」:「請給這個API必須通過SSL」, 「結果「:[], 」狀態「: 」REQUEST_DENIED「 }

用於調用網絡服務的網址:

http://maps.googleapis.com/maps/api/geocode/json?key=my_key=Rua+Vergueiro,+1883,+S%C3%A3o+Paulo,+Brazil&sensor=true

方法用於撥打網絡服務:

enter code here 

public static String httpPost(String urlStr) throws Exception { 
    String novaUrl = urlStr.trim(); 

    novaUrl = urlStr.replaceAll(" ", "+"); 
    novaUrl = novaUrl.replaceAll("\r", ""); 
    novaUrl = novaUrl.replaceAll("\t", ""); 
    novaUrl = novaUrl.replaceAll("\n", ""); 

    URL url = new URL(novaUrl); 
    HttpURLConnection conn = (HttpURLConnection) url.openConnection(); 

    conn.setRequestMethod("POST"); 
    conn.setDoOutput(true); 
    conn.setDoInput(true); 
    conn.setUseCaches(false); 
    conn.setAllowUserInteraction(false); 

    conn.setRequestProperty("Content-Type", "application/x-www-form-urldecoded"); 

    // Create the form content 
    OutputStream out = conn.getOutputStream(); 
    Writer writer = new OutputStreamWriter(out, "UTF-8"); 
    writer.close(); 
    out.close(); 

    // Buffer the result into a string 
    BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); 
    StringBuilder sb = new StringBuilder(); 
    String line; 

    while ((line = rd.readLine()) != null) { 
     sb.append(line); 
    } 

    rd.close(); 
    conn.disconnect(); 

    Spanned retorno = Html.fromHtml(sb.toString()); 

    return retorno.toString(); 
} 

如何解決此問題?

謝謝。

回答

0

請嘗試使用此URL。僅僅因爲http和https而出錯。 https用於安全線路。

https://maps.googleapis.com/maps/api/geocode/json?key=my_key=Rua+Vergueiro,+1883,+S%C3%A3o+Paulo,+Brazil&sensor=true

現在,當你點擊這個你會得到一些錯誤,這樣的.. 所提供的API密鑰無效。

爲此,您只需提供從Google控制檯檢索到的正確API密鑰。

+0

現在而言,我收到此錯誤:{ 「ERROR_MESSAGE」: 「此網站或IP沒有被授權使用該API密鑰」, 「結果」: [], 「status」:「REQUEST_DENIED」 } – user2952653

+0

如提及請交叉檢查您正在使用的API密鑰..請張貼您的清單文件。 – AndroidHacker

0

你給出的網址:: https://maps.googleapis.com/maps/api/geocode/json?key=my_key=Rua+Vergueiro,+1883,+S%C3%A3o+Paulo,+Brazil&sensor=true

here key=my_key Here is the problem, please provide correct API key and you problem will be solved. 
+1

我刪除了我的鑰匙只能發佈de url。 – user2952653

+0

請修正 –

+0

修改後的代碼,修復url後,我得到以下錯誤:{ 「error_message」:「本網站或IP未被授權使用此API密鑰。」, 「results」:[], 「status」:「REQUEST_DENIED」 } – user2952653