As long as you app uses oath and is verified you can build and play private playlists as if you were the user of the account [for that account]. Using the youtube v3 api and the .player api. If not authenticated properly for whatever reason, you can run into situations where the api lets you create a private playlist as a user of the account but the list is empty within the player api.
also, you can actually play private video:
@SuppressLint("StaticFieldLeak")
private void loadUploadedVideos() {
if (mChosenAccountName == null) {
return;
}
Log.d(TAG, "loadUploads");
showProgressDialog();
new AsyncTask<Void, Void, List<VideoData>>() {
@Override
protected List<VideoData> doInBackground(Void... voids) {
try {
YouTube youtube = new YouTube.Builder(transport, jsonFactory,
credential).setApplicationName(Constants.APP_NAME)
.build();
/*
* Now that the user is authenticated, the app makes a
* channels list request to get the authenticated user's
* channel. Returned with that data is the playlist id for
* the uploaded videos.
* https://developers.google.com/youtube
* /v3/docs/channels/list
*/
ChannelListResponse clr = youtube.channels()
.list("contentDetails").setMine(true).execute();
// Get the user's uploads playlist's id from channel list
// response
String uploadsPlaylistId = clr.getItems().get(0)
.getContentDetails().getRelatedPlaylists()
.getUploads();
List<VideoData> videos = new ArrayList<VideoData>();
// Get videos from user's upload playlist with a playlist
// items list request
PlaylistItemListResponse pilr = youtube.playlistItems()
.list("id,contentDetails")
.setPlaylistId(uploadsPlaylistId)
.setMaxResults(50L).execute();
List<String> videoIds = new ArrayList<String>();
// Iterate over playlist item list response to get uploaded
// videos' ids.
for (PlaylistItem item : pilr.getItems()) {
videoIds.add(item.getContentDetails().getVideoId());
}
// Get details of uploaded videos with a videos list
// request.
VideoListResponse vlr = youtube.videos()
.list("id,snippet,status")
.setId(TextUtils.join(",", videoIds)).execute();
// Add only the public videos to the local videos list.
for (Video video : vlr.getItems()) {
//if ("public".equals(video.getStatus().getPrivacyStatus())) {
VideoData videoData = new VideoData();
videoData.setVideo(video);
videos.add(videoData);
//}
}
// Sort videos by title
Collections.sort(videos, new Comparator<VideoData>() {
@Override
public int compare(VideoData videoData,
VideoData videoData2) {
return videoData.getTitle().compareTo(
videoData2.getTitle());
}
});
return videos;
} catch (final GooglePlayServicesAvailabilityIOException availabilityException) {
showGooglePlayServicesAvailabilityErrorDialog(availabilityException
.getConnectionStatusCode());
} catch (UserRecoverableAuthIOException userRecoverableException) {
startActivityForResult(
userRecoverableException.getIntent(),
REQUEST_AUTHORIZATION);
} catch (IOException e) {
Utils.logAndShow(MainActivity.this, Constants.APP_NAME, e);
}
catch (Exception e) {
Log.e(TAG, e.getMessage());
}
return null;
}
@Override
protected void onPostExecute(List<VideoData> videos) {
if (videos == null) {
hideProgressDialog();
return;
}
if (mMyUploadsFragment != null)
mMyUploadsFragment.setUploads(videos);
hideProgressDialog();
}
}.execute((Void) null);
}
Also once authenticated, youtube prime features are available in the player api. Nice. The trick seems to be to log the Youtube user into the youtube app on the phone as well as using the same creds in your own app.
anyway any playlist the app is authenticated to play on android can be played this way:
public void onPlaylistSelected(PlaylistData playlist) {
try {
mPlaylistData = playlist;
//Intent intent = YouTubeIntents.createPlayPlaylistIntent(this, playlist.getId());
Intent intent = YouTubeIntents.createOpenPlaylistIntent(this, playlist.getId());
startActivity(intent);
} catch (ActivityNotFoundException e) {
Log.w(TAG,e.getMessage());
Toast.makeText(this, R.string.warn_install_yt,Toast.LENGTH_LONG).show();
}
}