【问题标题】:Error on using googmaps api使用 googmaps api 时出错
【发布时间】:2014-01-13 19:54:42
【问题描述】:

我在尝试使用 google api maps 中的网络服务时遇到以下错误:

{ "error_message" : "对该 API 的请求必须通过 SSL。", “结果” : [], “状态”:“REQUEST_DENIED” }

用于调用网络服务的 url:

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();
}

如何解决这个问题?

谢谢。

【问题讨论】:

    标签: android google-maps google-maps-android-api-2


    【解决方案1】:

    尝试使用此网址。错误只是因为 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 密钥。

    【讨论】:

    • 现在,我收到此错误:{ "error_message" : "此站点或 IP 无权使用此 API 密钥。", "results" : [], "status" : "REQUEST_DENIED" }
    • 如前所述,请交叉检查您正在使用的 API 密钥。请发布您的清单文件。
    【解决方案2】:

    您给定的网址 :: 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.
    

    【讨论】:

    • 我删除了我的密钥只是为了发布 de url。
    • 修复网址后,我收到以下错误:{ "error_message" : "此站点或 IP 无权使用此 API 密钥。", "results" : [], "status" : "REQUEST_DENIED" }
    猜你喜欢
    • 2017-02-26
    • 1970-01-01
    • 2016-02-15
    • 2012-12-26
    • 2018-12-04
    • 2014-12-14
    • 2015-04-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多