我试图在Android中使用YouTube API v3获得我的YouTube帐户下的所有频道详细信息。下面是相同的代码:
YouTube youtube = new YouTube.Builder(transport, jsonFactory,
credential).setApplicationName(Constants.APP_NAME)
.build();
ChannelListResponse clr = youtube.channels()
.list("contentDetails").setMine(true).execute();
Log.d("","Channel count = "+clr.getItems().size());
目前,我在我的帐户下配置了2个通道。但是上面的行总是将通道计数打印为1。
关于如何使用API获得所有通道细节的任何想法?
试试下面的代码,它来自https://developers.google.com/youtube/v3/code_samples/java
// Construct a request to retrieve the current user's channel ID.
// See https://developers.google.com/youtube/v3/docs/channels/list
YouTube.Channels.List channelRequest = youtube.channels().list("contentDetails");
channelRequest.setMine(true);
// In the API response, only include channel information needed
// for this use case.
channelRequest.setFields("items/contentDetails");
ChannelListResponse channelResult = channelRequest.execute();
List<Channel> channelsList = channelResult.getItems();
if (channelsList != null) {
// The user's default channel is the first item in the list.
String channelId = channelsList.get(0).getId();
//USE FOR LOOP HERE TO RETRIEVE ALL CHANNELS
}
谢谢。