我正在使用HTTP Client Library for Java访问 Google 自定义搜索 API 并执行搜索。
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);
}
尽管它有效,但我总是收到此警告:
com.google.api.client.googleapis.services.AbstractGoogleClient WARNING: Application name is not set. Call Builder#setApplicationName.
如何使用 Java 的 HTTP 客户端库设置应用程序名称?
最佳答案
您应该使用Customsearch.Builder而不是 Customsearch 构造函数。示例:
Customsearch customsearch = new Builder(httpTransport, jsonFactory, null).setApplicationName("your application name").build();
关于java - 如何使用 Java 的 HTTP 客户端库设置应用程序名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33649414/