0

Java 用 HTTP クライアント ライブラリを使用して Google Custom Search 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 クライアント ライブラリを使用してアプリケーション名を設定するにはどうすればよいですか?

4

1 に答える 1

4

Customsearch コンストラクターの代わりにCustomsearch.Builderを使用する必要があります。例:

Customsearch customsearch = new Builder(httpTransport, jsonFactory, null).setApplicationName("your application name").build();
于 2015-11-11T12:23:39.557 に答える