Android版谷歌图书API - 访问未配置 [英] Google Books API for Android - Access Not Configured
问题描述
我使用谷歌图书API KEY为Android通过我的Android应用程序加载图书数据。但是,我得到如下的错误。
不过,
- 如果我删除我的API CONSOLE证书的查询工作(例如让所有应用程序的API KEY接受)。虽然我的{} SHA1 {包名}信息,我把是正确的。
- 这工作,如果我使用的API密钥的浏览器,而不是
所以,我能理解,我无法发送键URL的HttpClient的方法的一部分。可能是我需要通过页眉或东西送。但我怎么也找不到。
任何人都可以帮助吗?
code:
字符串link = \"https://www.googleapis.com/books/v1/volumes?key=MY_KEY&q=\"+query+\"&projection=full&langRestrict=en&maxResults=1\";
HTTPGET GET =新HTTPGET(链接);
的HttpParams httpParameters =新BasicHttpParams();
INT timeoutConnection = 10000;
HttpConnectionParams.setConnectionTimeout(httpParameters,timeoutConnection);
HttpConnectionParams.setSoTimeout(httpParameters,timeoutConnection);
HttpClient的HttpClient的=新DefaultHttpClient(httpParameters);
HTT presponse响应= httpclient.execute(获取);
HttpEntity实体= response.getEntity();
查询:
<$p$p><$c$c>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结果:
{
错误:{
错误:
{
域:usageLimits
原因:accessNotConfigured
消息:访问未配置
}
]
code:403,
消息:访问未配置
}
}
有关人可能关注......我把我的API密钥的头,而且它现在工作..我不知道这是否是正确的方法它虽然...
字符串link =https://www.googleapis.com/books/v1/volumes?q=\"+params;
InputStream为= NULL;
尝试
{
INT timeoutConnection = 10000;
网址URL =新的URL(链接);
HttpURLConnection的CON =(HttpURLConnection类)url.openConnection();
con.setConnectTimeout(timeoutConnection);
con.setReadTimeout(timeoutConnection);
con.setRequestProperty(钥匙,API_KEY);
如果(con.getResponse code()!= HttpURLConnection.HTTP_OK){
publishProgress(错误conneting。);
}
是= con.getInputStream();
}
I am using google books API KEY for android to load book data via my android application. But I am getting error listed below.
However, - The query works if I delete certificates from my API CONSOLE (e.g. make API KEY acceptable for all Applications). Though my {SHA1};{package name} information that I put is correct. - This works if I use API KEY for browser instead.
Hence, what I can understand, I can't send KEY as a part of url in httpclient method. May be I need to send via header or something. But I can't find how.
Anybody can help please?
CODE:
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();
Query:
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
Result:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "accessNotConfigured",
"message": "Access Not Configured"
}
],
"code": 403,
"message": "Access Not Configured"
}
}
For whom it may concern ... I send my API key in header, and it is now working.. I am not sure whether this is the proper way to it though ...
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版谷歌图书API - 访问未配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!