Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class WarsawDeveloperJava {
- public static void main(String[] args) throws Exception {
- String searchText = "Warsaw java developer";
- String key = "CUSTOM_SEARCH_API_KEY";
- String cx = "SEARCH_ENGINE_ID";
- JsonFactory jsonFactory = new JacksonFactory();
- HttpRequestInitializer httpRequestInitializer = new HttpRequestInitializer() {
- @Override
- public void initialize(HttpRequest request) throws IOException {
- }
- };
- Customsearch customsearch = new Customsearch(new NetHttpTransport(), jsonFactory, httpRequestInitializer);
- Customsearch.Cse.List list = customsearch.cse().list(searchText);
- list.setCx(cx);
- list.setCr("countryPL"); //country origin of search result
- list.setDateRestrict("m2"); //results should be no older than 2 months
- list.setKey(key);
- Search results = list.execute();
- List listResult = (List) results.getItems();
- Iterator iterator = listResult.iterator();
- while(iterator.hasNext()) {
- Result next = (Result)iterator.next();
- System.out.println(next.getLink());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement