public void method1(){
String search = "NASA latest research";
String charset = "UTF-8";
try{
//Reader reader = new InputStreamReader(new URL(the url).openStream());
// Reader reader = new InputStreamReader(new URL(google).openStream(), charset);
Reader reader = new InputStreamReader(new URL(google+ URLEncoder.encode(search, charset)).openStream(), charset);
GoogleResults results = new Gson().fromJson(reader, GoogleResults.class);
//List<com.google.api.services.customsearch.model.Result> result = new Gson().fromJson(reader, List.class);
System.out.println(results.getResponseData().getResults().get(0).getTitle());
System.out.println(results.getResponseData().getResults().get(0).getUrl());
}catch(MalformedURLException urle){
urle.printStackTrace();
}
catch(UnsupportedEncodingException ence){
ence.printStackTrace();
}
catch(IOException ioe){
ioe.printStackTrace();
}
}
(2) String google = "the url";
public void search0(){
try{
GoogleSearchQueryFactory factory = GoogleSearchQueryFactory.newInstance("MY-KEY-HERE");
WebSearchQuery query = factory.newWebSearchQuery();
PagedList<WebResult> response = query.withQuery("Latest from NASA").list();
System.out.println(response.getCurrentPageIndex());
System.out.println(response.getEstimatedResultCount());
System.out.println(response.getMoreResultsUrl());
System.out.println(response.getPages());
for (WebResult result : response) {
System.out.println(result.getTitle());
System.out.println(result.getContent());
System.out.println(result.getUrl());
System.out.println("=======================================");
}
}catch (Exception e) {
e.printStackTrace();
}
}and
(3) and a third and fourth approach but to no avail...
None of the above would work and all return the same e. does it mean this can work only via the :com.google.api.services.customsearch.Customsearch. well ,I have tried that too but with compiler errors on these deprecated mthods:
I really need a urgent help.Thanks in Advance !! Really grateful thanks
my email is : kade...@gmail.com