因此,我尝试在YouTube上的频道中插入订阅者和观看次数。我怎么做?我很擅长这样做,所以请记住:)
我已经设置了YouTube API并获得了我的API密钥。
我也有以下代码的网址。
我该怎么做:
{
"kind": "youtube#channelListResponse",
"etag": "REMOVED",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#channel",
"etag": "REMOVED",
"id": "REMOVED",
"statistics": {
"viewCount": "13398211",
"commentCount": "28",
"subscriberCount": "182758",
"hiddenSubscriberCount": false,
"videoCount": "84"
}
}
]
}

进入我需要的信息?提前谢谢!
答案 0 :(得分:1)
这是您需要的请求:
YouTube youTube = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), null).setApplicationName("yourAppName").build();
YouTube.Channels.List channelListRequest = youTube.channels().list("statistics");
channelListRequest.setKey(DEVELOPER_KEY);
channelListRequest.setId(channelID);
channelListRequest.setFields("items/statistics(viewCount, subscriberCount)");
ChannelListResponse channelListResponse = channelListRequest.execute();
Channel channel = channelListResponse.getItems().get(0);
此时您有Channel对象,其中包含您需要的数据。您可以轻松地从此对象获取数据。
BigInteger viewCount = channel .getStatistics().getViewCount();
BigInteger subscriberCount = channel.getStatistics().getSubscriberCount();