Google custom search Api example java

Google custom search Api example java

Are you showing the right products, to the right shoppers, at the right time? Contact us to know more.

Rate this article

Share this article

Read google custom search API example java for more information.

The Google API client libraries, which are available in many popular programming languages, make it easy to use the Custom Search JSON API. You can use the Google API Client Library for Java to use the custom search API in custom search api example java


Build a fully customizable Search without any coding

Google custom search API example in java

The following code might not be a proper way of working it out but it gives you the result links of google search. You just need to parse the output. 

public static void main(String[] args) throws Exception {

    String key="YOUR KEY";
    String qry="Android";
    URL url = new URL(
            ""+key+ "&cx=013036536707430787589:_pqjad5hr1a&q="+ qry + "&alt=json");
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setRequestProperty("Accept", "application/json");
    BufferedReader br = new BufferedReader(new InputStreamReader(

    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


GCS Alternative at $9


Leave a Reply

Avatar placeholder

Your email address will not be published.

You may also like