I'm trying to use the java client for the Google custom search api but couldn't find any sample tutorials on the web. Can someone provide a simple example for me to get started? Thank you!
With Google Cloud Operations you can create custom dashboards, set up alerts, and access metrics data programmatically. To access Custom Search JSON API usage data in Google Cloud Operations, select "Resource type: Consumed API" and filter on "service = 'customsearch.googleapis.com'" in the Query Builder.
Google Web Search API has been deprecated and replaced with Custom Search API (see http://code.google.com/apis/websearch/).
You can get an API key by visiting https://code.google.com/apis/console and clicking "API Access". You will then need to switch on the custom search API on the "Services" tab.
I want to make a correction here.
customsearch.setKey("YOUR_API_KEY_GOES_HERE");
does not work for client lib 1.6 but following does work
Customsearch customsearch = new Customsearch(new NetHttpTransport(), new JacksonFactory());
try {
com.google.api.services.customsearch.Customsearch.Cse.List list = customsearch.cse().list("YOUR_SEARCH_STRING_GOES_HERE");
list.setKey("YOUR_API_KEY_GOES_HERE");
list.setCx("YOUR_CUSTOM_SEARCH_ENGINE_ID_GOES_HERE");
Search results = list.execute();
List<Result> items = results.getItems();
for(Result result:items)
{
System.out.println("Title:"+result.getHtmlTitle());
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With