我使用 Eclipse Kepler 和 Youtube Data Api v3。
我正在尝试使用以下方法获取 channel 的订阅者数量:
Channel channel = new Channel();
channel.getStatistics().getSubscriberCount();
但这似乎是获取此信息的错误方式。
有人可以告诉我如何获取 channel 订阅者数量吗?
最佳答案
确保您使用正确的客户端库。此示例基于 YouTube Data API v3
pom.xml
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-youtube</artifactId>
<version>v3-rev125-1.19.1</version>
</dependency>
SubscriberCount.java
HttpRequestInitializer httpRequestInitializer = new HttpRequestInitializer() {
public void initialize(HttpRequest request) throws IOException {
}
};
YouTube youTube = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), httpRequestInitializer)
.setApplicationName("<Your-Application-Name>")
.build();
YouTube.Channels.List search = youTube.channels().list("statistics");
search.setForUsername("codeherenow");
search.setKey("<Insert-API-Key>");
ChannelListResponse response = search.execute();
List<Channel> channels = response.getItems();
for (Channel channel : channels) {
System.out.println(channel.getStatistics().getSubscriberCount());
}
关于java - 如何使用 Youtube Data API v3 获取 Youtube channel 订阅者数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21665532/