我需要计算我在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());
}
最佳答案
Youtube API中的新更新是您不能再使用Channels: list来计数订阅者。mySubscribers
( bool(boolean) 值)
This parameter has been deprecated. This parameter can only be used in a properly authorized request. Use the subscriptions.list method and its mySubscribers parameter to retrieve a list of subscribers to the authenticated user's channel.
尝试使用以下URI请求制作REST call in Java:
GET https://www.googleapis.com/youtube/v3/subscriptions?part=snippet&mySubscribers=true&fields=pageInfo&key={SERVER_API_KEY}
totalResults键保存订阅者数,这是响应的示例:
{
"pageInfo": {
"totalResults": 2,
"resultsPerPage": 5
}
}
在这里,totalResults是订户数。
关于java - 我无法计算我的订阅者的Youtube API V3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39106358/