import java.io.IOException;
import java.util.ArrayList;
import com.google.soap.search.GoogleSearch;
import com.google.soap.search.GoogleSearchFault;
import com.google.soap.search.GoogleSearchResult;
import com.google.soap.search.GoogleSearchResultElement;
public class MyGoogleSearch {
private static String CLIENT_KEY = "YOU_HAVE_TO_GET_YOUR_OWN_KEY_FROM_GOOGLE";
public static ArrayList doSearch(String queryString) throws IOException {
ArrayList searchResults = new ArrayList();
GoogleSearch search = new GoogleSearch();
search.setKey(CLIENT_KEY);
try {
search.setQueryString(queryString.trim());
GoogleSearchResult results = search.doSearch();
GoogleSearchResultElement[] resultElements = results.getResultElements();
for (int i = 0; i<resultElements.length; i++) {
searchResults.add(new SearchResultBean(resultElements[i].getTitle(), resultElements[i].getURL(), resultElements[i].getSnippet()));
}
} catch (GoogleSearchFault f) {
throw new IOException("The call to the Google Web APIs failed: " + f.getMessage());
} catch (Exception e) {
throw new IOException("Thread Problem.");
}
return searchResults;
}
}