检索单个视频的观看次数 - Youtube API V3.0 - JavaScript [英] Retrieving individual videos view count - Youtube API V3.0 - JavaScript
问题描述
我一直在尝试通过以下方法获取我查询的视频的观看次数:
I've been trying to get the view count on videos that I query through the following method:
function search() {
var request = gapi.client.youtube.search.list({
part: 'snippet',
channelId: 'IRRELEVANT',
order: 'date',
maxResults: '25'
});
request.execute(function(response){
YoutubeResponse(response);
});
虽然文档告诉我每个视频都有一个 statistics
部分,但在 snippet
之后我有 __proto__
,我猜这意味着有某处出错?还是 API 发生了变化?基本上我需要这 25 个最新视频的观看次数......
While the documentation tells me that there's a statistics
portion to every video, after the snippet
I have __proto__
which I guess means there was an error somewhere? or did the API change? Essentially I need the view count of those 25 most recent videos...
我尝试将 part: 'snippet'
更改为 part: 'statistics'
但得到一个 code: -32602
...
I tried changing part: 'snippet'
to part: 'statistics'
but got back a code: -32602
...
感谢您的帮助,
干杯!
显然 search.list
没有统计数据",而是我需要单独搜索每个视频......问题是,当使用谷歌的尝试"功能时(https://developers.google.com/youtube/v3/docs/videos/list#try-it) 当你在底部的字段"部分询问统计数据时,它没有做任何事情......所以我很困惑我怎么能得到视图计数&所有 25 个视频的长度(如果单独或同时全部 - 最好 -)
Apparently the search.list
doesn't have the "statistics" but rather I need to search every video individually... The thing is, when using googles "Try It" feature (https://developers.google.com/youtube/v3/docs/videos/list#try-it) when you ask for the statistics in the "Fields" part at the bottom, it doesn't do anything... So I am VERY confused as to how the heck can I get the view counts & length of all 25 videos (if individually or all at once - preferably-)
推荐答案
您提供的链接 https://developers.google.com/youtube/v3/docs/videos/list#try-it 为我工作.获取持续时间和视图计数:填写部分:contentDetails,statistics 和 id:以逗号分隔的视频 ID 列表,例如:TruIq5IxuiU,-VoFbH8jTzE,RPNDXrAvAMg,gmQmYc9-zcg
The link you gave https://developers.google.com/youtube/v3/docs/videos/list#try-it is working for me. To get duration and viewCount: Fill in for part: contentDetails,statistics and for id: a comma-separated-list of video-id's like: TruIq5IxuiU,-VoFbH8jTzE,RPNDXrAvAMg,gmQmYc9-zcg
这将创建一个请求:
GET https://www.googleapis.com/youtube/v3/videos?part=contentDetails,statistics&id=TruIq5IxuiU,-VoFbH8jTzE,RPNDXrAvAMg,gmQmYc9-zcg&key={YOUR_API_KEY}
GET https://www.googleapis.com/youtube/v3/videos?part=contentDetails,statistics&id=TruIq5IxuiU,-VoFbH8jTzE,RPNDXrAvAMg,gmQmYc9-zcg&key={YOUR_API_KEY}
这篇关于检索单个视频的观看次数 - Youtube API V3.0 - JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!