I need to fetch video id, title and description for n items using the below code. But the below code doesn't fetch the searchResponse. It doesn't even prints the search response. I tried the url manually via curl and it fetches the result correctly. The same url its not working via below code. I didn't get any detailed error in log. Refer the attached log below.
https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCja8sZ2T4ylIqjggA1Zuukg&order=date&maxResults=50&key=dhsdhsbdbd// Sample code
public void fetchVideosFromChannel(String channelId) { log.trace("Starting fetchVideosFromChannel for channel ID: {}", channelId); try { List<String> parts = new ArrayList<String>(4); parts.add("snippet"); YouTube.Search.List search = youtube.search().list(parts); search.setChannelId(channelId); search.setMaxResults(50L); search.setOrder("date"); search.setKey(fetchYouTubeAPIKey()); // Execute the search request SearchListResponse searchResponse = search.execute(); log.trace("Search response: {}", searchResponse); List<SearchResult> searchResults = searchResponse.getItems(); log.trace("Number of search results: {}", searchResults != null ? searchResults.size() : 0); if (searchResults != null && !searchResults.isEmpty()) { for (SearchResult searchResult : searchResults) { String videoId = searchResult.getId().getVideoId(); String videoTitle = searchResult.getSnippet().getTitle(); String videoDescription = searchResult.getSnippet().getDescription(); log.trace("Video ID: {}", videoId); log.trace("Title: {}", videoTitle); log.trace("Description: {}", videoDescription); } } else { log.trace("No results found."); } } catch (Exception e) { log.error("There was an error fetching YouTube videos: {}", e.getMessage(), e); } }Log:
[Test worker] TRACE com.palmtree.youtube.test.YouTubeClientTest - initialize YouTube API Keys[Test worker] TRACE com.palmtree.youtube.YouTubeClient - Starting fetchVideosFromChannel for channel ID: UCja8sZ2T4ylIqjggA1Zuukg[Test worker] TRACE com.palmtree.youtube.YouTubeClient - YouTube initialized@