如何使用 javascript API 获得观看次数最多的管视频? [英] How to get most viewed you tube video using javascript API?

查看:32
本文介绍了如何使用 javascript API 获得观看次数最多的管视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取按观看次数最多的 YouTube 视频排序的视频列表.我一直在尝试以下代码,但没有返回任何响应.

I am trying to get the list of video sorted by most viewed you tube video.I have been trying the following code but it is not returning any response.

var request = gapi.client.youtube.search.list({
                part: 'snippet,contentDetails,statistics',
                q: query,
                maxResults: count,
                order:'viewCount'
            });
request.execute(onSearchResponse);

上面的代码没有返回任何响应.有人可以将我重定向到正确的方向吗?我已经查看了文档.

Above code does not return any response.Can someone please redirect me in right direction I have already looked into documentation.

https://developers.google.com/youtube/v3/docs/搜索/列表

推荐答案

使用 YouTube API v3 (并修改此 answer),您可以使用此请求网址获取观看次数最多的 YouTube 视频.

Using the YouTube API v3 (and modifying the parameters supplied in this answer), you can use this request URL for get the most viewed YouTube video.

https://www.googleapis.com/youtube/v3/search?key=<YOUR_API_KEY>&part=snippet&order=viewcount&maxResults=1

以下信息取自 YouTube 数据 API -官方文档:

  • 密钥:您的 API 密钥.
  • part:part 参数指定 API 响应将包含的一个或多个搜索资源属性的逗号分隔列表.将参数值设置为snippet.
  • 订购1:在这种情况下,使用viewcount.
  • ma​​xResults:指定结果集中应返回的最大项目数.可接受的值为 0 到 50(含).默认值为 5.
  • key: your API key.
  • part: The part parameter specifies a comma-separated list of one or more search resource properties that the API response will include. Set the parameter value to snippet.
  • order1: in this case, is used viewcount.
  • maxResults: specifies the maximum number of items that should be returned in the result set. Acceptable values are 0 to 50, inclusive. The default value is 5.

1 链接文档说order 参数中只允许使用这些值:

1 Linked documentation says that only these values are allowed in the order parameter:

  • 日期:资源按创建日期倒序排列.
  • 评级:资源按评级从高到低排序.
  • 相关性:根据资源与搜索查询的相关性对资源进行排序.这是此参数的默认值.
  • title:资源按标题的字母顺序排序.
  • videoCount:频道按上传的视频数量降序排列.
  • viewCount:资源按从高到低的查看次数排序.对于直播,视频在直播期间按同时观看的人数排序.
  • date: Resources are sorted in reverse chronological order based on the date they were created.
  • rating: Resources are sorted from highest to lowest rating.
  • relevance: Resources are sorted based on their relevance to the search query. This is the default value for this parameter.
  • title: Resources are sorted alphabetically by title.
  • videoCount: Channels are sorted in descending order of their number of uploaded videos.
  • viewCount: Resources are sorted from highest to lowest number of views. For live broadcasts, videos are sorted by number of concurrent viewers while the broadcasts are ongoing.

这篇关于如何使用 javascript API 获得观看次数最多的管视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆