Google api 谷歌自定义搜索API错误

Google api 谷歌自定义搜索API错误,google-api,google-custom-search,httpexception,Google Api,Google Custom Search,Httpexception,我使用谷歌云平台进行免费试用 在java应用程序中使用自定义搜索API 我在应用程序中编写以下代码 URL url = new URL("https://www.googleapis.com/customsearch/v1?key="+key+ "&cx=013036536707430787589:_pqjad5hr1a&q="+ qry + "&alt=json"); HttpURLConnection conn = (HttpURLConnection) ur

我使用谷歌云平台进行免费试用

在java应用程序中使用自定义搜索API

我在应用程序中编写以下代码

 URL url = new URL("https://www.googleapis.com/customsearch/v1?key="+key+ 
 "&cx=013036536707430787589:_pqjad5hr1a&q="+ qry + "&alt=json");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");
BufferedReader br = new BufferedReader(new InputStreamReader(
        (conn.getInputStream())));

String output;
System.out.println("Output from Server .... \n");

while ((output = br.readLine()) != null) {

    if(output.contains("\"link\": \"")){                
        String link=output.substring(output.indexOf("\"link\": \"")+("\"link\": \"").length(), output.indexOf("\","));

        System.out.println(link);       //Will print the google search links
    }     
}
conn.disconnect();       
有时它会给我一个结果,然后它会给我以下错误,不管查询字符串是什么,这个错误都会发生

线程“main”java.io.IOException中的异常:服务器返回了URL的HTTP响应代码:403????? 位于sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1839) 位于sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440) 位于sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)


请问问题出在哪里?

403
是谷歌禁止的错误——这意味着你发送的请求太多太快,他们认为你在使用机器人或自动化

如果您在浏览器中加载该查询并查看请求,请快速点击刷新,直到看到html响应显示

We're sorry...

... but your computer or network may be sending automated queries. To protect our users, we can't process your request right now.

See Google Help for more information.