Search code examples
freebase

Freebase API User Rate Limit Exceeded


I got the foloowing error and I do not know how to solve it. I read the page but my problem is not the same as the writer problem (space in URL).

com.google.api.client.http.HttpResponseException: 403 Forbidden
{
"error": {
 "errors": [
{
"domain": "usageLimits",
"reason": "userRateLimitExceededUnreg",
"message": "User Rate Limit Exceeded. Please sign up",
"extendedHelp": "https://code.google.com/apis/console"
}
],
  "code": 403,
  "message": "User Rate Limit Exceeded. Please sign up"
  }
  }

I checked the page 1; they mentioned "Freebase allows developers a free quota of up to 100,000 (one hundred thousand) read calls per day per person" and I only quota 49886 read calls.Then I got this error and I do not know how to solve the problem.


Solution

  • I created a server key for using Freebase API. Also, I defined my query in follwoing way:

    String query="https://www.googleapis.com/freebase/v1/topic"+mId+"?key=xxx";            
    GenericUrl url = new GenericUrl(query);
    HttpRequest request = requestFactory.buildGetRequest(url)
    HttpResponse httpResponse = request.execute();
    JSONObject response = (JSONObject)parser.parse(httpResponse.parseAsString());
    

    The mId is mid in Freebase corpus. In addition, I add the flowing catch based on this pageto prevent error since in each second we can only send 10 requests to Freebase server.

    catch (HttpResponseException e) {
                 if (e.getStatusCode()== 403
                        && (e.getContent().contains("userRateLimitExceededUnreg")
                            || e.getContent().contains("uotaExceeded"))) {
                     System.out.println("sleep");
                     Thread.sleep((2^ n) *1000 + randomGenerator.nextInt(1001));
    
                  }