Google Custom Search API

旧巷老猫 提交于 2019-12-23 04:15:15

问题


How should one approach on using Google Custom Search API using JAVA? What is the appropriate use of Google Search Appliance API?


回答1:


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();   
    }

  }


来源:https://stackoverflow.com/questions/11319705/google-custom-search-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!