void refresh() throws IOException { Disposable disposable = // Observable.just(ytApi.playlistItems() .list(YOUTUBE_PLAYLIST_PART) .setPlaylistId(YOUTUBE_PLAYLIST_ID) .setPageToken(null) .setFields(YOUTUBE_PLAYLIST_FIELDS) .setMaxResults(YOUTUBE_PLAYLIST_MAX_RESULTS) .setKey(API_KEY) // ) .map(AbstractGoogleClientRequest::execute) .map(PlaylistItemListResponse::getItems) .flatMap(playlistItems -> Observable.fromIterable(playlistItems) .map(item -> item.getSnippet().getResourceId().getVideoId())) .toList() .map(ids -> ytApi.videos().list(YOUTUBE_VIDEOS_PART).setFields(YOUTUBE_VIDEOS_FIELDS) // .setKey(API_KEY).setId(TextUtils.join(",", ids)).execute()) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnError( throwable -> Log.e(TAG, "accept() called with: throwable = [" + throwable + "]")) .doOnSuccess( response -> Log.d(TAG, "accept() called with: response = [" + response + "]")) .onErrorReturnItem(new VideoListResponse()) // Bad work around .doOnSuccess(liveData::setValue) .subscribe(); disposables.add(disposable); } }
.setPlaylistId(uploadsPlaylistId) .setMaxResults(20l).execute(); List<String> videoIds = new ArrayList<String>();
playlistItemListResponse = mYouTubeDataApi.playlistItems() .list(YOUTUBE_PLAYLIST_PART) .setPlaylistId(playlistId) .setPageToken(nextPageToken) .setFields(YOUTUBE_PLAYLIST_FIELDS) .setMaxResults(YOUTUBE_PLAYLIST_MAX_RESULTS) .setKey(ApiKey.YOUTUBE_API_KEY) .execute(); } catch (IOException e) { e.printStackTrace();
/** * Returns a collection of playlist items that match the API request parameters. You can retrieve * all of the playlist items in a specified playlist or retrieve one or more playlist items by their * unique IDs. * * Create a request for the method "playlistItems.list". * * This request holds the parameters needed by the youtube server. After setting any optional * parameters, call the {@link List#execute()} method to invoke the remote operation. * * @param part The part parameter specifies a comma-separated list of one or more playlistItem resource properties * that the API response will include. If the parameter identifies a property that contains * child properties, the child properties will be included in the response. For example, in a * playlistItem resource, the snippet property contains numerous fields, including the title, * description, position, and resourceId properties. As such, if you set part=snippet, the * API response will contain all of those properties. * @return the request */ public List list(java.lang.String part) throws java.io.IOException { List result = new List(part); initialize(result); return result; }
public List<SimpleResult> getPlayListItems(String playlistCode) { List<SimpleResult> playlist = new ArrayList<>(); try { YouTube.PlaylistItems.List playlistRequest = youtube.playlistItems().list("id,contentDetails,snippet"); playlistRequest.setPlaylistId(playlistCode); playlistRequest.setKey(search.getKey()); playlistRequest.setFields("items(contentDetails/videoId,snippet/title,snippet/publishedAt),nextPageToken,pageInfo"); String nextToken = ""; do { playlistRequest.setPageToken(nextToken); PlaylistItemListResponse playlistItemResult = playlistRequest.execute(); playlist.addAll(playlistItemResult.getItems().stream().map(playlistItem -> new SimpleResult(playlistItem.getContentDetails().getVideoId(), playlistItem.getSnippet().getTitle())).collect(Collectors.toList())); nextToken = playlistItemResult.getNextPageToken(); } while (nextToken != null); } catch (IOException e) { e.printStackTrace(); } return playlist; }