1
我使用Youtube API v3按關鍵字搜索視頻。我目前正在使用此代碼:如何使用youtube API v3使用Java獲取視頻的URL
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示例,我很迷茫。
任何幫助?
感謝
@無顯示名稱:感謝您的編輯。在平板電腦上使用代碼功能很困難。 :) –
@Mark: - 它發生:-) – HaveNoDisplayName