I am learning using youtube data api v3 to show list of playlists and further show list of videos of each play list from below link https://developers.google.com/youtube/v3
I was able to get playlist for a channel id. And further each playlist, list of videos.
Before that I need channel id to do rest of operations. The input would be name of the channel and output should be details which includes unique channel id. Below is the code snip that I was trying but I always get null result. Where as other part of code (by hard coding channel id) works great.
public class GetChannelInfoAsyncTask extends AsyncTask<String, Void, ChannelListResponse> {
private static final String YOUTUBE_CHANNELLIST_PART = "snippet";
private static final String YOUTUBE_CHANNELLIST_FIELDS = "items(id,snippet(title))";
private YouTube mYouTubeDataApi;
public GetChannelInfoAsyncTask(YouTube api) {
mYouTubeDataApi = api;
}
@Override
protected ChannelListResponse doInBackground(String... params) {
final String channelName = params[0];
ChannelListResponse channelListResponse = null;
try {
channelListResponse = mYouTubeDataApi.channels()
.list(YOUTUBE_CHANNELLIST_PART)
.setForUsername(channelName)
.setAlt(ApiKey.YOUTUBE_API_KEY)
.execute();
} catch (IOException e) {
e.printStackTrace();
}
return channelListResponse;
}
}
Referring to https://developers.google.com/youtube/v3/docs/channels/list and tried EXECUTE option with list (by YouTube username) gives 200(OK) success. but with above code its always null.