【发布时间】:2014-04-08 04:22:41
【问题描述】:
我正在使用 Youtube API v3 按关键字搜索视频。我目前正在使用此代码:
YouTube youtube;
youtube = new YouTube.Builder(GoogleNetHttpTransport.newTrustedTransport(), new JacksonFactory(), new HttpRequestInitializer() {
public void initialize(HttpRequest request) throws IOException {
}}).setApplicationName("youtube-cmdline-search-sample").build();
// query term.
String keyword = request.getParameter("keyword");
// api key
String apiKey = "my-api-key";
// Define the API request for retrieving search results.
YouTube.Search.List search = youtube.search().list("id,snippet");
// Set your developer key from the Google Cloud Console for
// non-authenticated requests. See:
// https://cloud.google.com/console
lstVideos.setKey(apiKey);
search.setKey(apiKey);
search.setQ(keyword);
// To increase efficiency, only retrieve the fields that the
// application uses.
search.setFields("items(id/kind,id/videoId,snippet/title,snippet/thumbnails/default/url)");
search.setMaxResults((long)10);
// Call the API and print results.
SearchListResponse searchResponse = search.execute();
List<SearchResult> searchResultList = searchResponse.getItems();
Iterator<SearchResult> itsearch = searchResultList.iterator();
这对我来说可以很好地获取一些数据,例如(id、缩略图等)。此代码可在Youtube v3 API examples 获得。
我在 stackoverflow (this) 上看到了一个基本相同的问题,但是.. 我不知道如何获取这些数据。我看不到任何 Java 示例,我很迷茫。
有什么帮助吗?
谢谢
【问题讨论】:
标签: list url search video youtube