当前我遇到了我的代码问题,在过去的3天里,我无法使用Google Places API成功完成删除请求,文档为here。Google Places API问题 - INVALID REQUEST
直到星期日为止,只要请求的地方符合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;
}
我刚刚遇到了JSON请求的问题,因为文档中的place ID键应该是“place_id”而不是“placeid”。在此处查看我的答案:http://stackoverflow.com/a/28287549/4448436 – 2015-02-02 22:03:10
placeid适用于Google API文档示例链接。但它不适用于我获得的ID。我为两者使用相同的API密钥。 – Talha 2017-06-13 07:37:52