Google Places API请求无效时出现java问题
目前,我的代码遇到了一个问题,在过去3天中,我无法使用Google Places API成功完成删除请求,有文档记录here
直到周日,只要请求的位置满足API中的条件,并且我收到的唯一响应是OK或REQUEST_DENIED表单,那么这段代码就会执行并运行,不会出现问题
然而,现在,每当我发送一个请求时,我收到的唯一响应都是无效请求的形式,这很不方便。根据我的理解,以及我之前对这段代码进行的测试,我遵守了他们要求的格式,所以我不明白为什么这不起作用
其他人能看看这段代码并告诉我与链接的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;
}
# 1 楼答案
发生在我身上的另一种情况是,我存储Google引用ID的数据类型是
string
(限制为255个字符),将列数据类型更改为text
修复了所有问题。无效的_请求响应通常来自错误的引用调用。谷歌也可以扩展引用ID的长度,你不会知道它没有正确地保存到数据库中# 2 楼答案
这对我很有用:
# 3 楼答案
就我个人而言,我收到了对我的Google API请求的无效请求响应,因为它们之间的间隔不够。我不得不在他们之间插入2秒钟的睡眠,这样他们才能工作
# 4 楼答案
我做错的是我使用了谷歌的'id'属性,但事实证明还有一个'place\u id',你必须使用place\u id,而不是'id'
# 5 楼答案
尝试按照文档中的建议刷新您的参考: https://developers.google.com/maps/documentation/places/
# 6 楼答案
我假设你已经用你的API密钥替换了这里的API密钥。尝试在developer console中获取新密钥,并确保“允许的IP地址”设置正确