문제

Currently I'm working with the Google Books API.

I write a simple request:

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;
}

and after that i except a 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;
}

But now the Problem, every Time i start a request i get the following:

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

But I have no Idea why. In the Api Console I enable the Book api, I have generated a new Api Key with the Project Name.

도움이 되었습니까?

해결책

OK, the Problem for this problem was that i have use the wrong api key, i had it for browser and android, i just copy the key after i test it in the browser. stupid from my side

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top