確保您使用的是正確的客戶端庫。這個例子是基於YouTube數據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());
}