我正在使用 google books API KEY for android 通过我的 android 应用程序加载图书数据。但是我收到下面列出的错误。
但是, - 如果我从我的 API CONSOLE 中删除证书(例如,使 API KEY 对所有应用程序都可接受),则查询有效。虽然我输入的 {SHA1};{package name} 信息是正确的。 - 如果我改用浏览器的 API KEY,这会起作用。
因此,据我所知,我不能在 httpclient 方法中将 KEY 作为 url 的一部分发送。可能是我需要通过标题或其他方式发送。但我找不到方法。
有人可以帮忙吗?
代码:
String link = "https://www.googleapis.com/books/v1/volumes?key=MY_KEY&q="+query+"&projection=full&langRestrict=en&maxResults=1";
HttpGet get = new HttpGet(link);
HttpParams httpParameters = new BasicHttpParams();
int timeoutConnection = 10000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
HttpConnectionParams.setSoTimeout(httpParameters, timeoutConnection);
HttpClient httpclient = new DefaultHttpClient(httpParameters);
HttpResponse response = httpclient.execute(get);
HttpEntity entity = response.getEntity();
查询:
https://www.googleapis.com/books/v1/volumes?key=MY_API_KEY&q=intitle:'The+Old+Man+And+The+Sea'+inauthor:'Ernest+Hemingway'&projection=full&langRestrict=en&maxResults=1
结果:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "accessNotConfigured",
"message": "Access Not Configured"
}
],
"code": 403,
"message": "Access Not Configured"
}
}
最佳答案
它可能与谁有关......我在 header 中发送了我的 API key ,它现在正在工作......不过我不确定这是否是正确的方法......
String link = "https://www.googleapis.com/books/v1/volumes?q="+params;
InputStream is = null;
try
{
int timeoutConnection = 10000;
URL url = new URL(link);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setConnectTimeout(timeoutConnection);
con.setReadTimeout(timeoutConnection);
con.setRequestProperty("key", "API_KEY");
if(con.getResponseCode() != HttpURLConnection.HTTP_OK){
publishProgress("Error conneting.");
}
is=con.getInputStream();
}
关于android - 适用于 Android 的 Google Books API - 访问权限未配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20825036/