在 Java 版 YouTube V3 API 中获取观看次数 [英] Get View Count in YouTube V3 API for java
问题描述
如何通过使用Java API
提供某个视频的videoID来获取某个YouTube视频的观看次数信息?
例如在他们提供的代码示例中,他们打印了不同的属性.如何添加打印查看计数?
Java 代码:
SearchResult singleVideo = iteratorSearchResults.next();ResourceId rId = singleVideo.getId();//确认结果代表一个视频.否则,//项目将不包含视频 ID.如果 (rId.getKind().equals("youtube#video")) {缩略图缩略图 = singleVideo.getSnippet().getThumbnails().getDefault();System.out.println("视频ID" + rId.getVideoId());System.out.println(" Title: " + singleVideo.getSnippet().getTitle());System.out.println(" 缩略图:" + thumb.getUrl());System.out.println("
------------------------------------------------------------
");
这是一个与我非常相似的问题,也没有回答:
在 Search.List 中获取 ViewCount - Youtube Data API v3
更新 30/9:根据 Youtube API 教程,视频资源可能包含以下部分:>
- 片段
- 内容详情
- 文件详情
- 玩家
- 处理详情
- 录音详情
- 统计数据
- 状态
- 建议
- 主题详情
但在 SearchResult 对象只暴露所有这些对象中的 getSnippet()
所以也许 API V3 还不支持所有这些统计属性??
好的,我知道了,代码是:
YouTube.Videos.List list = youtube.videos().list("statistics");list.setId("kffacxfA7G4");list.setKey("你的私有API KEY");视频 v = list.execute().getItems().get(0);System.out.println("查看次数为:"+v.getStatistics().getViewCount());
顺便说一句,这段视频的观看次数超过了十亿次——贾斯汀·比伯的规则!(-;
How can I get the information of how many views a certain video of YouTube has by providing the videoID of it using Java API
?
for example in the code sample that their provide they print different properties. How can I add printing the view Count?
Java code:
SearchResult singleVideo = iteratorSearchResults.next();
ResourceId rId = singleVideo.getId();
// Confirm that the result represents a video. Otherwise, the
// item will not contain a video ID.
if (rId.getKind().equals("youtube#video")) {
Thumbnail thumbnail = singleVideo.getSnippet().getThumbnails().getDefault();
System.out.println(" Video Id" + rId.getVideoId());
System.out.println(" Title: " + singleVideo.getSnippet().getTitle());
System.out.println(" Thumbnail: " + thumbnail.getUrl());
System.out.println("
-------------------------------------------------------------
");
here is a very similar question to mine, also unanswered:
Get ViewCount in Search.List - Youtube Data API v3
update 30/9: According to Youtube API tutorial the video resource may contain the following parts:
- snippet
- contentDetails
- fileDetails
- player
- processingDetails
- recordingDetails
- statistics
- status
- suggestions
- topicDetails
but in the SearchResult object only expose getSnippet() out of all of them
I also couldn't use a different part except the 'snippet' in the API Explorer that google provides.
So maybe all these statistics properties are not supported yet by API V3??
OK I got it the code to do it is:
YouTube.Videos.List list = youtube.videos().list("statistics");
list.setId("kffacxfA7G4");
list.setKey("your private API KEY");
Video v = list.execute().getItems().get(0);
System.out.println("The view count is: "+v.getStatistics().getViewCount());
This video BTW exceed the billion views - Justim Bieber rules! (-;
这篇关于在 Java 版 YouTube V3 API 中获取观看次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!