我正在尝试在Google地方添加一个事件,并且返回的JSON状态中的请求无效,并且此端点已在error_message中删除。今天早上它工作正常,但现在它不再起作用了。
我试图在请求中使用HTTP来查看它是否返回请求被拒绝但是这样做没有,它总是返回无效请求。
这是我的代码:
private final String EVENT_URL =
"https://maps.googleapis.com/maps/api/place/event/add/json?";
private JSONObject uploadEvent() {
JSONObject jsonobj = new JSONObject();
StringEntity sEntity = null;
try {
jsonobj.put("duration", duration);
jsonobj.put("reference", reference);
jsonobj.put("summary", description);
if(url.length() > 0){
jsonobj.put("url", url);
}
sEntity = new StringEntity(jsonobj.toString());
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppostreq = new HttpPost(getUrlEvent());
httppostreq.setEntity(sEntity);
String responseText;
JSONObject JSON = null;
try {
HttpResponse httpresponse = httpclient.execute(httppostreq);
responseText = EntityUtils.toString(httpresponse.getEntity());
JSON = new JSONObject(responseText);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return json;
}
private String getUrlEvent(){
//genero la solicitud como la debajo descrita
StringBuilder urlString = new StringBuilder(EVENT_URL);
urlString.append("&sensor=false&key=" + API_KEY);
return urlString.toString();
}
有人可以帮助我吗?
答案 0 :(得分:0)
尝试
sEntity.setContentEncoding("UTF-8");
sEntity.setContentType("application/json");
httppostreq.addHeader("Content-Type", "application/json");
答案 1 :(得分:0)
注意:2014年9月3日已弃用事件和地点。弃用期已结束。截至2015年2月10日, API不再接受事件或碰撞操作,也不再返回 场所搜索或放置详细信息回复中的事件。