title: Get all videos of a YouTube Playlist in Java
body: <p><strong>Context</strong> I'm working with Android Studio (Java). I want to obtain all the videos of a given playlist (or 50, I will get all the other after).</p>
  
  <p><strong>Problem</strong> I see people using url like 
  <code>https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&amp;maxResults=50&amp;playlistId=PLiEwZfNgb4fVrRzTonlVEMj6DB2Nmzg2M&amp;key=AIzaSyC2_YRcTE9916fsmA0_KRnef43GbLzz8m0</code>
   but I don't know how to implement this in Java. I follow some tuto and I got a way to get information totally different like :</p>
  
  <pre><code>YouTube.Search.List query;
  query = youtube.search().list("id,snippet");
        query.setKey(MY_API_KEY);
        query.setMaxResults((long)20);
        query.setType("video");
        query.setFields("items(id/videoId,snippet/title,snippet/description,snippet/thumbnails/default/url)");
  </code></pre>
  
  <p>And I really don't understand how do I get something else than a search.
  Most of documentation is in english only...</p>
  
  <p><strong>EDIT</strong>
  Ok, so I continued to try, I think I got a near solution, but I got an error.</p>
  
  <pre><code>private YouTube youtube;
  private YouTube.PlaylistItems.List playlistItemRequest;
  private String PLAYLIST_ID = "PLiEwZfNgb4fVrRzTonlVEMj6DB2Nmzg2M";
  public static final String KEY = "AIzaSyC2_YRcTE9916fsmA0_KRnef43GbLzz8m0";
  
  // Constructor
  public YoutubeConnector(Context context)
  {
      youtube = new YouTube.Builder(new NetHttpTransport(),
              new JacksonFactory(), new HttpRequestInitializer()
      {
          @Override
          public void initialize(HttpRequest hr) throws IOException {}
      }).setApplicationName(context.getString(R.string.app_name)).build();
  }
  
  public List&lt;VideoItem&gt; result()
  {
      List&lt;PlaylistItem&gt; playlistItemList = new ArrayList&lt;PlaylistItem&gt;();
      try
      {
      /* HERE MUST BE MY PROBLEM ! */
          playlistItemRequest = youtube.playlistItems().list("snippet");
          playlistItemRequest.setPlaylistId(PLAYLIST_ID);
          playlistItemRequest.setFields("items(id/videoId,snippet/title,snippet/description,snippet/thumbnails/default/url),nextPageToken,pageInfo");
          playlistItemRequest.setKey(KEY);
          String nextToken = "";
          do {
              playlistItemRequest.setPageToken(nextToken);
              PlaylistItemListResponse playlistItemResult = playlistItemRequest.execute();
  
              playlistItemList.addAll(playlistItemResult.getItems());
  
              nextToken = playlistItemResult.getNextPageToken();
          } while (nextToken != null);
      }catch(IOException e)
      {
          Log.d("YC", "Could not initialize: "+e);
      }
  //[...]
  }
  </code></pre>
  
  <p>Here is the error I got :
  <code>
  {
  "code" : 400, 
      "errors" : [ {
          "domain" : "global", 
          "location" : "fields", 
          "locationType" : "parameter", 
          "message" : "Invalid field selection videoId", 
          "reason" : "invalidParameter"
       } ],
       "message" : "Invalid field selection videoId"
  }</code></p>
  
  <p><strong>EDIT 2</strong> Thanks to : Martijn Woudstra.
  Correct line was :</p>
  
  <pre><code>playlistItemRequest = youtube.playlistItems().list("snippet,contentDetails");
  //[...]
  playlistItemRequest.setFields("items(snippet/title,snippet/description,snippet/thumbnails/default/url,contentDetails/videoId),nextPageToken,pageInfo");
  //[...]
  videoItem.setId(item.getContentDetails().getVideoId());
  </code></pre>