【问题标题】:Youtube API V3 I Can't Count My SubscriberYoutube API V3 我数不清我的订阅者
【发布时间】:2016-08-23 16:26:14
【问题描述】:

我需要计算我在 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 youtube-api subscription youtube-data-api


【解决方案1】:

Youtube API 的新更新是你不能再使用Channels: list 来统计订阅者了。

mySubscribers(布尔值)

此参数已被弃用。该参数只能用于 适当授权的请求。使用 subscriptions.list 方法及其 mySubscribers 参数来检索列表 已验证用户频道的订阅者。

尝试使用此 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 初学者,我不知道该怎么做。你能帮帮我吗?
  • 我也不怎么做Android。我建议你了解你的工具的来龙去脉:)
  • 感谢您的回答。但是我没有太多时间学习,你能教我吗?我真的需要这个代码。
猜你喜欢
  • 2015-08-23
  • 1970-01-01
  • 2015-10-03
  • 2017-07-25
  • 1970-01-01
  • 2013-12-02
  • 1970-01-01
  • 2017-12-14
相关资源
最近更新 更多