问题
I am trying to get all the channels of user via using Youtube data api v3 in android, i am using Channels: list https://developers.google.com/youtube/v3/docs/channels/list#http-request get the all channels ,
public static void getChannelID(YouTube youtube){
try {
Log.i(MainActivity.APP_NAME, "Requesting ChannelID.");
com.google.api.services.youtube.YouTube.Channels.List Channel = youtube.channels().list("id,snippet,contentDetails");
Channel.setMine(true);
// In the API response, only include channel information needed
// for this use case.
Channel.setFields("items/contentDetails, items/id, items/snippet");
// List request is executed and list of broadcasts are returned
ChannelListResponse returnedListResponse = Channel.execute();
// Since the API request specified a unique channel ID, the API
// response should return exactly one channel. If the response does
// not contain a channel, then the specified channel ID was not found.
List<Channel> channelList = returnedListResponse.getItems();
Log.e("=========channelList.size=========", ""+channelList.size());
for (int i = 0; i < channelList.size(); i++) {
if (channelList != null) {
// The user's default channel is the first item in the list.
String channelId = channelList.get(i).getId();
Log.e("=========channelId=========", ""+channelId);
Log.e("=========getContentDetails=========", ""+channelList.get(i).getContentDetails());
Log.e("=========getSnippet=========", ""+channelList.get(i).getSnippet());
//Log.i("getStatus", ""+channelList.get(i).getStatus());
//Log.i("getKind", ""+channelList.get(i).getKind());
//USE FOR LOOP HERE TO RETRIEVE ALL CHANNELS
}
}
}catch (GoogleJsonResponseException e) {
Log.e("GoogleJsonResponseException", e.toString());
System.err.println("GoogleJsonResponseException code: "
+ e.getDetails().getCode() + " : "+ e.getDetails().getMessage());
e.printStackTrace();
}catch (IOException e) {
System.err.println("IOException: " + e.getMessage());
e.printStackTrace();
} catch (Throwable t) {
System.err.println("Throwable: " + t.getMessage());
t.printStackTrace();
}
}
Currently, I have configured 2 channels under my account. But the above line always prints the channel count as 1. Any idea on how to get all channel details using API?
来源:https://stackoverflow.com/questions/36349606/getting-all-channels-using-youtube-data-api-v3