【发布时间】:2015-11-19 12:26:28
【问题描述】:
j.setUrl("https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false&key=AIzaSyA712jyN6NY0VXSGf8zgXfXSRhq01O8RLY");
这是我的 json 网址和我的密钥。它总是给我 status request denied 。我尝试使用调试密钥库和新密钥库制作很多密钥,但没有任何效果。这是谷歌的示例网址。它对我不起作用。 如果您想提供有关新密钥的解决方案,请向我提供有关如何获取有效调试密钥的详细过程。请非常详细。 如果您想提供有关传感器参数的解决方案,它已经在那里。 如果你想要json解析器文件如下
package com.json;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;
import android.os.AsyncTask;
public class JSONParser extends AsyncTask<Void, Void, JSONObject> {
static InputStream is = null;
static JSONObject jObj = null;
static String json = "";
private String url;
// constructor
public JSONParser() {
}
@Override
protected JSONObject doInBackground(Void... params) {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(getUrl());
HttpResponse httpResponse = null;
try {
httpResponse = httpClient.execute(httpPost);
} catch (ClientProtocolException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
HttpEntity httpEntity = httpResponse.getEntity();
try {
is = httpEntity.getContent();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BufferedReader reader = null;
try {
reader = new BufferedReader(
new InputStreamReader(is, "iso-8859-1"), 8);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
json = sb.toString();
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// return JSON String
return jObj;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}
编辑:我查看了我的 api 控制台的报告,它显示发出了请求,因为我看到请求我认为密钥不是无效的,因为它正确地引导到我的 api 控制台。如果我错了,请纠正我?
编辑 2 :所以我尝试了一切,现在创建了一个新的 ID,为我的调试密钥库获得了一个新的 api 密钥,使用 url 和 json 解析器类创建了一个全新的项目。我仍然收到请求被拒绝。有人可以帮我吗?
【问题讨论】:
-
在你的 url 中尝试用 search 它为我的工作替换附近搜索并使用此链接获取调试密钥 stackoverflow.com/questions/5262695/…
-
还是不行,我仍然收到请求被拒绝
-
我已经获得了 sha1 证书,然后是密钥,但即使这样做了 5 次,我仍然会收到此错误
-
您使用的密钥无效
-
我已按照以下步骤获取密钥:- 1.) 获取 debug.keystore 文件的 sha1 证书 2.) 转到 apis 控制台并单击创建新的 android 密钥 3.) 输入sha1证书,加';'到它,然后添加包名称,在我的例子中是 com.json 4.)获取新密钥,复制它并在 url 中使用它。我错过了什么,还剩下什么?
标签: android android-emulator google-places-api