Get View Count in YouTube V3 API for java(在 YouTube V3 API for java 中获取观看次数)
问题描述
如何通过 Java API
提供某个 YouTube 视频的 videoID 来获取该视频的观看次数信息?
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 代码:
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("
-------------------------------------------------------------
");
这里有一个与我非常相似的问题,也没有答案:
在 Search.List 中获取 ViewCount - Youtube Data API v3
here is a very similar question to mine, also unanswered:
Get ViewCount in Search.List - Youtube Data API v3
30/9 更新:根据 Youtube API tutorial,视频资源可能包含以下部分:
update 30/9: According to Youtube API tutorial the video resource may contain the following parts:
- 片段
- 内容详情
- 文件详情
- 播放器
- 处理详情
- 录音详情
- 统计数据
- 状态
- 建议
- 主题详情
但在 SearchResult 对象只公开所有的 getSnippet()
but in the SearchResult object only expose getSnippet() out of all of them
除了 部分m/youtube/v3/youtube.search.list?part=statistics&q=like%20a%20virgin&_h=2&"google 提供的 rel="nofollow noreferrer">API Explorer.
I also couldn't use a different part except the 'snippet' in the API Explorer that google provides.
那么 API V3 可能还不支持所有这些统计属性??
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! (-;
这篇关于在 YouTube V3 API for java 中获取观看次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 YouTube V3 API for java 中获取观看次数


基础教程推荐
- 验证是否调用了所有 getter 方法 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- Java Swing计时器未清除 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01