app/src/main/java/com/smedic/tubtub/YouTubeSearch.java
public void searchPlaylists() {
        new Thread() {
            public void run() {
                youtube = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), credential)
                        .setApplicationName(appName).build();
                try {
                    ChannelListResponse channelListResponse = youtube.channels().list("snippet").setMine(true).execute();

                    List<Channel> channelList = channelListResponse.getItems();
                    if (channelList.isEmpty()) {
                        Log.d(TAG, "Can't find user channel");
                    }
                    Channel channel = channelList.get(0);

                    YouTube.Playlists.List searchList = youtube.playlists().list("id,snippet,contentDetails,status").setKey(Config.YOUTUBE_API_KEY);

                    searchList.setChannelId(channel.getId());
                    searchList.setFields("items(id,snippet/title,snippet/thumbnails/default/url,contentDetails/itemCount,status)");
                    searchList.setMaxResults((long) 50);

                    PlaylistListResponse playListResponse = searchList.execute();
                    List<Playlist> playlists = playListResponse.getItems();

                    if (playlists != null) {

                        Iterator<Playlist> iteratorPlaylistResults = playlists.iterator();

                        if (!iteratorPlaylistResults.hasNext()) {
                            Log.d(TAG, " There aren't any results for your query.");
                        }

                        ArrayList<YouTubePlaylist> youTubePlaylistList = new ArrayList<>();

                        while (iteratorPlaylistResults.hasNext()) {
                            Playlist playlist = iteratorPlaylistResults.next();

                            YouTubePlaylist playlistItem = new YouTubePlaylist(playlist.getSnippet().getTitle(),
                                    playlist.getSnippet().getThumbnails().getDefault().getUrl(),
                                    playlist.getId(),
                                    playlist.getContentDetails().getItemCount(),
                                    playlist.getStatus().getPrivacyStatus());
                            youTubePlaylistList.add(playlistItem);
                        }

                        youTubePlaylistsReceiver.onPlaylistsReceived(youTubePlaylistList);
                    }
                } catch (UserRecoverableAuthIOException e) {
                    playlistFragment.startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }.start();

    }
/**
     * /**
     * Search playlists for a current user
     */
Search playlists for a current user
Search playlists for a current user
public void searchPlaylists() {
        new Thread() {
            public void run() {
                youtube = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), credential)
                        .setApplicationName(appName).build();
                try {
                    ChannelListResponse channelListResponse = youtube.channels().list("snippet").setMine(true).execute();
                    List<Channel> channelList = channelListResponse.getItems();
                    if (channelList.isEmpty()) {
                        Log.d(TAG, "Can't find user channel");
                    }
                    Channel channel = channelList.get(0);
                    YouTube.Playlists.List searchList = youtube.playlists().list("id,snippet,contentDetails,status").setKey(Config.YOUTUBE_API_KEY);
                    searchList.setChannelId(channel.getId());
                    searchList.setFields("items(id,snippet/title,snippet/thumbnails/default/url,contentDetails/itemCount,status)");
                    searchList.setMaxResults((long) 50);
                    PlaylistListResponse playListResponse = searchList.execute();
                    List<Playlist> playlists = playListResponse.getItems();
                    if (playlists != null) {
                        Iterator<Playlist> iteratorPlaylistResults = playlists.iterator();
                        if (!iteratorPlaylistResults.hasNext()) {
                            Log.d(TAG, " There aren't any results for your query.");
                        }
                        ArrayList<YouTubePlaylist> youTubePlaylistList = new ArrayList<>();
                        while (iteratorPlaylistResults.hasNext()) {
                            Playlist playlist = iteratorPlaylistResults.next();
                            YouTubePlaylist playlistItem = new YouTubePlaylist(playlist.getSnippet().getTitle(),
                                    playlist.getSnippet().getThumbnails().getDefault().getUrl(),
                                    playlist.getId(),
                                    playlist.getContentDetails().getItemCount(),
                                    playlist.getStatus().getPrivacyStatus());
                            youTubePlaylistList.add(playlistItem);
                        }
                        youTubePlaylistsReceiver.onPlaylistsReceived(youTubePlaylistList);
                    }
                } catch (UserRecoverableAuthIOException e) {
                    playlistFragment.startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }.start();
    }
public void searchPlaylists ( ) { new Thread ( ) { public void run ( ) { youtube = new YouTube . Builder ( new NetHttpTransport ( ) , new JacksonFactory ( ) , credential ) . setApplicationName ( appName ) . build ( ) ; try { ChannelListResponse channelListResponse = youtube . channels ( ) . list ( "snippet" ) . setMine ( true ) . execute ( ) ; List < Channel > channelList = channelListResponse . getItems ( ) ; if ( channelList . isEmpty ( ) ) { Log . d ( TAG , "Can't find user channel" ) ; } Channel channel = channelList . get ( 0 ) ; YouTube . Playlists . List searchList = youtube . playlists ( ) . list ( "id,snippet,contentDetails,status" ) . setKey ( Config . YOUTUBE_API_KEY ) ; searchList . setChannelId ( channel . getId ( ) ) ; searchList . setFields ( "items(id,snippet/title,snippet/thumbnails/default/url,contentDetails/itemCount,status)" ) ; searchList . setMaxResults ( ( long ) 50 ) ; PlaylistListResponse playListResponse = searchList . execute ( ) ; List < Playlist > playlists = playListResponse . getItems ( ) ; if ( playlists != null ) { Iterator < Playlist > iteratorPlaylistResults = playlists . iterator ( ) ; if ( ! iteratorPlaylistResults . hasNext ( ) ) { Log . d ( TAG , " There aren't any results for your query." ) ; } ArrayList < YouTubePlaylist > youTubePlaylistList = new ArrayList < > ( ) ; while ( iteratorPlaylistResults . hasNext ( ) ) { Playlist playlist = iteratorPlaylistResults . next ( ) ; YouTubePlaylist playlistItem = new YouTubePlaylist ( playlist . getSnippet ( ) . getTitle ( ) , playlist . getSnippet ( ) . getThumbnails ( ) . getDefault ( ) . getUrl ( ) , playlist . getId ( ) , playlist . getContentDetails ( ) . getItemCount ( ) , playlist . getStatus ( ) . getPrivacyStatus ( ) ) ; youTubePlaylistList . add ( playlistItem ) ; } youTubePlaylistsReceiver . onPlaylistsReceived ( youTubePlaylistList ) ; } } catch ( UserRecoverableAuthIOException e ) { playlistFragment . startActivityForResult ( e . getIntent ( ) , REQUEST_AUTHORIZATION ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } } } . start ( ) ; }
Search playlists for a current user
Search playlists for a current user