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 中获取观看次数


基础教程推荐
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 降序排序:Java Map 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01