Advertisement
Guest User

GarciaPL

a guest
Oct 16th, 2014
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. public class WarsawDeveloperJava {
  2.     public static void main(String[] args) throws Exception {
  3.  
  4.         String searchText = "Warsaw java developer";
  5.         String key = "CUSTOM_SEARCH_API_KEY";
  6.         String cx = "SEARCH_ENGINE_ID";
  7.  
  8.         JsonFactory jsonFactory = new JacksonFactory();
  9.         HttpRequestInitializer httpRequestInitializer = new HttpRequestInitializer() {
  10.  
  11.             @Override
  12.             public void initialize(HttpRequest request) throws IOException {
  13.  
  14.             }
  15.         };
  16.         Customsearch customsearch = new Customsearch(new NetHttpTransport(), jsonFactory, httpRequestInitializer);
  17.         Customsearch.Cse.List list = customsearch.cse().list(searchText);
  18.         list.setCx(cx);
  19.         list.setCr("countryPL"); //country origin of search result
  20.         list.setDateRestrict("m2"); //results should be no older than 2 months
  21.         list.setKey(key);
  22.  
  23.         Search results = list.execute();
  24.         List listResult = (List) results.getItems();
  25.  
  26.         Iterator iterator = listResult.iterator();
  27.         while(iterator.hasNext()) {
  28.             Result next = (Result)iterator.next();
  29.             System.out.println(next.getLink());
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement