1

目前我正在使用 Google Books API。

我写了一个简单的请求:

public static String request(String url)
{
    DefaultHttpClient client = new DefaultHttpClient();

    client.getConnectionManager().getSchemeRegistry().register(
            new Scheme("SSLSocketFactory", SSLSocketFactory.getSocketFactory(), 443));
    HttpGet method = new HttpGet(url);
    String data = null;
    try
    {
        BasicHttpResponse response = (BasicHttpResponse) client.execute(method);
        data = EntityUtils.toString(response.getEntity());
    }
    catch (Exception e)
    {
        System.out.println("IOException in HTTPSRequest.request: " + e.toString());
    }
    return data;
}

之后我除了一个JSonArray:

static final String baseURL = "https://www.googleapis.com/books/v1/volumes?key=" + APIKey + "&q=";

public static String getURL(String searchstring)
{
    return baseURL + searchstring;
}

public static JSONObject getJSONObjectFromString(String jsonString)
{
    JSONParser parser = new JSONParser();
    JSONObject object = null;
    try
    {
        object = (JSONObject) parser.parse(jsonString);
    }
    catch (Exception e)
    {
        System.out.println("ParseException in GoogleBooksHelper.getJSONObjectFromString");
    }
    return object;
}

public static JSONArray getItemsAsJSONArray(String jsonString)
{
    JSONObject object = getJSONObjectFromString(jsonString);
    JSONArray items = (JSONArray) object.get("items");
    return items;
}

但是现在的问题是,每次我开始一个请求时,我都会得到以下信息:

{"error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "accessNotConfigured",
    "message": "Access Not Configured"
   }
  ],
  "code": 403,
  "message": "Access Not Configured"
 }
}

但我不知道为什么。在 Api 控制台中,我启用了 Book api,我生成了一个带有项目名称的新 Api 密钥。

4

1 回答 1

1

好的,这个问题的问题是我使用了错误的 api 密钥,我有它用于浏览器和 android,我只是在浏览器中测试后复制密钥。在我身边愚蠢

于 2013-12-03T11:02:08.080 回答