JsonObjectRequest returns 无
JsonObjectRequest returns nothing
我想使用 Google 个地点 API 来获取并显示特定区域的餐馆列表。
我试过了,但它什么也没显示,我也没有错误:
String url="https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-45.730425,4.839938&radius=500&types=food&key=AIzaSyD8vqYPQzJRJa3rOLSC1wqIaUxSN0WcvGc";
JsonObjectRequest jsObjRequest = new JsonObjectRequest
(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d("json", response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub
Log.d("json", "not working");
}
});
如果您在网络浏览器中尝试 URL,它会告诉您问题所在:
{
"error_message": "This API project is not authorized to use this API. Please ensure this API is activated in the Google Developers Console: https://console.developers.google.com/apis/api/places_backend?project=_",
"html_attributions": [],
"results": [],
"status": "REQUEST_DENIED"
}
看来您还没有在开发者控制台中启用 API。
转到https://console.developers.google.com/
然后点击你想要的项目,在左侧菜单中点击 API manager,然后点击 library,在顶部搜索 Places 然后点击你想要的结果,从这里你应该看到一个显示 "ENABLE"
的按钮
点击它,然后再次尝试您的请求,它应该可以工作。
编辑:
响应中提供了一个link供您使用:
https://console.developers.google.com/apis/api/places_backend
单击它,应该会在该页面上提供启用 API 的选项
我想使用 Google 个地点 API 来获取并显示特定区域的餐馆列表。 我试过了,但它什么也没显示,我也没有错误:
String url="https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=-45.730425,4.839938&radius=500&types=food&key=AIzaSyD8vqYPQzJRJa3rOLSC1wqIaUxSN0WcvGc";
JsonObjectRequest jsObjRequest = new JsonObjectRequest
(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d("json", response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub
Log.d("json", "not working");
}
});
如果您在网络浏览器中尝试 URL,它会告诉您问题所在:
{
"error_message": "This API project is not authorized to use this API. Please ensure this API is activated in the Google Developers Console: https://console.developers.google.com/apis/api/places_backend?project=_",
"html_attributions": [],
"results": [],
"status": "REQUEST_DENIED"
}
看来您还没有在开发者控制台中启用 API。
转到https://console.developers.google.com/
然后点击你想要的项目,在左侧菜单中点击 API manager,然后点击 library,在顶部搜索 Places 然后点击你想要的结果,从这里你应该看到一个显示 "ENABLE"
的按钮点击它,然后再次尝试您的请求,它应该可以工作。
编辑:
响应中提供了一个link供您使用:
https://console.developers.google.com/apis/api/places_backend
单击它,应该会在该页面上提供启用 API 的选项