How to set the application name using the HTTP Client Library for Java?

好久不见. 提交于 2019-12-13 04:36:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!