Skip to content Skip to sidebar Skip to footer

How Can I Get A List Of Videos Available From A Particular Youtube Channel?

How can I get a list of videos available from a particular YouTube channel, using the API?

Solution 1:

Basically every youtube channels has three section: Uploads, Playlist, Liked Videos. Had done some work with the playlist of a channels. Used youtube api version 3.Sharing my code:

First get the Playlists from a channel:

privatevoidgetPlayList() {
    YouTube.Playlists.List playLists;
    try {
        playLists = youtube.playlists().list("id,status,snippet");//youtube is the Youtube object, already initialised
        playLists.setChannelId(channelID);//channelID is the channel id which you want to fetch
        playLists.setFields("items(id,status/privacyStatus,snippet(title,thumbnails/default/url))");
        playLists.setMaxResults((long) 50);

        AsynRequestClass asynRequestClass = new AsynRequestClass();
        asynRequestClass.execute(playLists);

    } catch (IOException e) {
        e.printStackTrace();
        Log.e(null, "Error occur " + e.toString());
    }
}
privateclassAsynRequestClassextendsAsyncTask<YouTube.Playlists.List, Void, PlaylistListResponse> {

    @Override
    protectedvoidonPreExecute() {
        super.onPreExecute();
        showProgressDialogWithTitle("Loading PlayList");
    }

    @Override
    protected PlaylistListResponse doInBackground(YouTube.Playlists.List... params) {
        PlaylistListResponse playlistListResponse = null;
        try {
            Log.d(null, "PlayListList: " + params[0]);
            playlistListResponse = params[0].execute();
            Log.d(null,"PlayListResponse: "+playlistListResponse);
            for (int i=0;i<playlistListResponse.getItems().size();i++){
            //PlayListIdentifier,PlayListTitle,PlayListThumbnails are ArrayList<String>, already allocated and initialised
                PlayListTitles.add(playlistListResponse.getItems().get(i).getSnippet().getTitle());
                PlayListThumbnails.add(playlistListResponse.getItems().get(i).getSnippet().getThumbnails().getDefault().getUrl());
                PlayListIdentifier.add(playlistListResponse.getItems().get(i).getId());
            }
        }catch (UserRecoverableAuthIOException e){
            startActivityForResult(e.getIntent(),REQUEST_AUTHORIZATION);

        }catch (IOException e) {
            e.printStackTrace();
        }
        returnnull;
    }

    @Override
    protectedvoidonPostExecute(PlaylistListResponse playlistListResponse){
        super.onPostExecute(playlistListResponse);
        hideProgressDialog();
        PlayListDataAdapter.notifyDataSetChanged();//PlayListDataAdapter is the data adapter
    }
}

Then get the playListItem or Videos:

privatevoidloadPlayListItem(){
    YouTube.PlaylistItems.List playListItemList = null;
    try {
        playListItemList =youtube.playlistItems().list("id,contentDetails,snippet,status");
        playListItemList.setPlaylistId(playListID);
        playListItemList.setFields("items(id,status/privacyStatus,snippet(title,thumbnails/default/url),contentDetails/regionRestriction)");
        playListItemList.setMaxResults((long) 50);
        AsyncRequestClass asyncRequestClass = new AsyncRequestClass();
        asyncRequestClass.execute(playListItemList);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
//Class for asynchronous taskprivateclassAsyncRequestClassextendsAsyncTask<YouTube.PlaylistItems.List, Void, PlaylistItemListResponse> {

    @Override
    protectedvoidonPreExecute() {
        super.onPreExecute();
        showProgressDialogWithTitle("Loading Video");
    }

    @Override
    protected PlaylistItemListResponse doInBackground(YouTube.PlaylistItems.List... params) {
        PlaylistItemListResponse playlistItemListResponse = null;
        try {
            Log.d(null, "PlayListListItem: " + params[0]);
            playlistItemListResponse = params[0].execute();
            Log.d(null,"PlayListItemListResponse: "+playlistItemListResponse);
            int size = playlistItemListResponse.getItems().size();
            for (int i=0;i<size;i++){
                if (!playlistItemListResponse.getItems().get(i).getStatus().getPrivacyStatus().equals("private")){
            //videoListIdentifier,videoListTitle,videoListThumbnails are ArrayList<String>, already allocated and initialised
                    videoTitles.add(playlistItemListResponse.getItems().get(i).getSnippet().getTitle());
                    videoThumbnails.add(playlistItemListResponse.getItems().get(i).getSnippet().getThumbnails().getDefault().getUrl());
                    videoIdentifier.add(playlistItemListResponse.getItems().get(i).getContentDetails().getVideoId());
                }
            }
        }catch (UserRecoverableAuthIOException e){
            startActivityForResult(e.getIntent(),REQUEST_AUTHORIZATION);

        }catch (IOException e) {
            e.printStackTrace();
        }
        returnnull;
    }

    @Override
    protectedvoidonPostExecute(PlaylistItemListResponse playlistItemListResponse) {
        super.onPostExecute(playlistItemListResponse);
        hideProgressDialog();
        videoListDataAdapter.notifyDataSetChanged();//videoListDataAdapter is the data adapter
    }
}

Hadn't worked with the other two(Uploads,Liked videos), but think it can be possible in a similar manner.

Post a Comment for "How Can I Get A List Of Videos Available From A Particular Youtube Channel?"