How should one approach on using Google Custom Search API using JAVA? What is the appropriate use of Google Search Appliance API?
Asked
Active
Viewed 4,995 times
1 Answers
3
Here is google custom search API Example. you need to download Libraries and example is here
public class Custom {
public static void main(String args[]) throws IOException {
String key="Replace with your API key";
String qry="batman";// search key word
URL url = new URL(
"https://www.googleapis.com/customsearch/v1?
key="+key+"&cx="Replace with unique ID"&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(url);
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);
}
}
conn.disconnect();
}
}

VICKY-TSC
- 405
- 2
- 5
- 19
-
the 403 is due to the API key. You need to create a new one from the Google Developper Console – Jonathan Lebrun Jul 28 '16 at 08:58