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 url 和我的密钥。它总是给我 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 解析器类创建了一个全新的项目。我仍然收到请求被拒绝。有人能帮我吗?