当前,我的代码遇到问题,在过去 3 天里,我无法使用 Google Places API 成功完成删除请求,此处记录。
直到周日,只要请求的位置满足 API 中的条件,这段代码就可以毫无问题地执行和运行,并且我收到的唯一响应是 OK 或 REQUEST_DENIED 形式。
然而,现在,每当我发送请求时,我收到的唯一响应都是 INVALID_REQUEST 形式的,至少可以说非常不方便。根据我的理解,以及我事先对此代码执行的测试,我遵守他们要求的格式,所以我不明白为什么这不起作用。
其他人可以查看此代码并告诉我与链接的 API 相比是否有任何问题?
public boolean delete(String reference)
{
try
{
System.out.println(reference);
String url = "https://maps.googleapis.com/maps/api/place/delete/xml?sensor=false&key=API_KEY_HERE";
String data = "<PlaceDeleteRequest>\n<reference>" + reference + "</reference>\n</PlaceDeleteRequest>";
System.out.println(data);
URL xmlUrl = new URL(url);
HttpPost request = new HttpPost(xmlUrl.toURI());
request.setEntity(new StringEntity(data));
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(request);
HttpEntity entity = response.getEntity();
BufferedReader input = new BufferedReader(new InputStreamReader(entity.getContent()));
String line = "";
while ((line = input.readLine()) != null)
{
System.out.println(line);
if (line.contains("<status>"))
{
String[] s1 = line.split(">");
String[] s2 = s1[1].split("<");
if (s2[0].equalsIgnoreCase("ok"))
{
return true;
}
else
{
return false;
}
}
}
input.close();
}
catch(Exception e)
{
return false;
}
return false;
}