我正在尝试使用 Android 中的 YouTube API v3 获取我的 YouTube 帐户下的所有 channel 详细信息。这是相同的代码。
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个 channel 。但上面的行始终将 channel 数打印为 1。
知道如何使用 API 获取所有 channel 详细信息吗?
提前致谢。
最佳答案
试试这个代码,它来自 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
}
谢谢。这可能对您有帮助。
关于java - 使用 YouTube API 获取 channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24824648/