[英]Using proxies with Google HTTP Client Library for Java
[英]How to set the application name using the HTTP Client Library for Java?
我正在使用Java的HTTP客戶端庫來訪問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警告:未設置應用程序名稱。 調用Builder#setApplicationName。
如何使用Java的HTTP客戶端庫設置應用程序名稱?
您應該使用Customsearch.Builder而不是Customsearch構造函數。 例:
Customsearch customsearch = new Builder(httpTransport, jsonFactory, null).setApplicationName("your application name").build();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.