本文介绍了如何使用HTTP客户端库for Java设置应用程序名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用来访问Google Custom Search API并执行搜索。
String key =...;
String cx =...;
String query =...;
//设置HTTP传输和JSON工厂
HttpTransport httpTransport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
Customsearch customsearch = new Customsearch(httpTransport,jsonFactory,null);
清单<结果> resultList = null;
尝试{
Customsearch.Cse.List list = customsearch.cse()。list(query);
list.setKey(key);
list.setCx(cx);
搜索结果= list.execute();
} catch(Exception e){
LOG.debug(Exception:+ e);
}
尽管它有效,但我始终得到这样的警告:
如何使用HTTP客户端库设置应用程序名称?
$ b $您应该使用而不是Customsearch构造函数。例如:$ pre $
Customsearch customsearch = new Builder(httpTransport,jsonFactory,null).setApplicationName(your application name)。build );
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:
How can I set the application name using the HTTP Client Library for Java?
解决方案
You should use the Customsearch.Builder instead of the Customsearch constructor. Example:
Customsearch customsearch = new Builder(httpTransport, jsonFactory, null).setApplicationName("your application name").build();
这篇关于如何使用HTTP客户端库for Java设置应用程序名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!