android - 适用于 Android 的 Google Books API - 访问权限未配置

标签 android google-api google-books

我正在使用 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/

相关文章:

Google Books API 的 json 遍历

android - 深层链接进入应用程序后的后退按钮不会返回到它来自的位置

android - SurfaceView 中的缩放和拖动功能

php - Google Youtube API稍后观看

javascript - setToken 不会在 Google API (gapi) 中切换 YouTube channel

javascript - 使用 YouTube 视频 ID 访问 YouTube 视频 URL

android - 如何在 Singleton 和 SharedPreferences 类中传递应用程序上下文

Android:从 GregorianCalendar 对象获取年、月、日

google-api - 为什么使用 Google Books API 返回不正确的 "pageCount"?

heroku - Google Books API 服务器不接受来自 Heroku 服务器的调用