问题
I am using the HTTP Client Library for Java to access the Google Custom Search API and perform a search.
String key = "...";
String cx = "...";
String query = "...";
// Set up the HTTP transport and JSON factory
HttpTransport httpTransport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
Customsearch customsearch = new Customsearch(httpTransport, jsonFactory,null);
List<Result> resultList = null;
try {
Customsearch.Cse.List list = customsearch.cse().list(query);
list.setKey(key);
list.setCx(cx);
Search results = list.execute();
}catch (Exception e) {
LOG.debug("Exception: " + e);
}
Although it works, I always get this warning:
com.google.api.client.googleapis.services.AbstractGoogleClient WARNING: Application name is not set. Call Builder#setApplicationName.
How can I set the application name using the HTTP Client Library for Java?
回答1:
You should use the Customsearch.Builder instead of the Customsearch constructor. Example:
Customsearch customsearch = new Builder(httpTransport, jsonFactory, null).setApplicationName("your application name").build();
来源:https://stackoverflow.com/questions/33649414/how-to-set-the-application-name-using-the-http-client-library-for-java