I’m having the “famous” error : Server returned HTTP response code: 403 for URL.
I have to send a lot’s of queries (+-2000) to fill my database. However, the 50-100 first work, then all the following trigger error 403. I can’t figure out why …
Here is my code :
public static ArrayList<String> querying(String name){
URL url = null;
String inputLine;
ArrayList<String> resultArray = new ArrayList<String>();
BufferedReader in;
try {
url = new URL(s);
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.addRequestProperty("User-Agent", "Mozilla/4.0");
in = new BufferedReader(new InputStreamReader(con.getInputStream()));
while ((inputLine = in.readLine()) != null) {
...
}
in.close();
con.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
return resultArray;
}
where s is :
"https://www.googleapis.com/freebase/v1/mqlread?query={\"id\":\"/en/"+name+"\", \"name\": null, \"type\":\"/base/popstra/celebrity\",\"/base/popstra/celebrity/friendship\": [{\"participant\": [] }] }".replace(" ", "")
I tried to find some information about this error on the web, but despite what I found (for example “addRequestProperty) it’s still not working.
The URL in your question suggests you’re not using an API key.
With an API key, you should be able to do 100k/10k reads/writes per day (according to Freebase documentation)
Without an API key your quota is limited to a much smaller number and you’ll receive a 403 response when you go over. This is to prevent abuse of the API infrastructure so everyone can get a fair share of API requests.
Please follow the instruction on Getting Started in the Freebase documentation to get an API key.