我正在使用YouTube API创建应用。在这里,我想列出与电子邮件ID相关的所有频道,所以我在下面的代码中写了这个。这段代码的问题是它只返回一个Channel(默认的一个)但我想要一个所有通道的列表。
以下是代码:
YouTube youTube = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest request) throws IOException {}
}).setApplicationName("YouTube").build();
try {
final YouTube.Channels.List list = youTube.channels().list("snippet,id");
list.setForUsername("USER_NAME");
list.setKey("API_KEY");
new Thread(new Runnable() {
@Override
public void run() {
try{
ChannelListResponse response = list.execute();
List<Channel> channelList = response.getItems();
Log.wtf("totalChannel", channelList.size()+"");
for (Channel channel: channelList){
Log.wtf("channel", channel.getSnippet().getTitle().toString());
Log.wtf("id", channel.getId().toString());
}
}catch (Exception ex){Log.wtf("exception", ex.toString());}
}
}).start();
}catch (Exception ex){Log.wtf("exception", ex.toString());}