在 Javascript 中通过 JSON 获取单个视频(不是提要)的 Youtube 信息 [英] Get Youtube information via JSON for single video (not feed) in Javascript
问题描述
所以我试图通过 JSON 格式从单个 youtube 视频中获取信息.就像标题描述类别一样,除了评论之外,我还能得到什么.我正在尝试在 Javascript 中执行此操作.我注意到下面的链接,但他们所有的例子都是如何从提要中获取视频信息.我想从单个视频中获取信息,前提是我知道它的 ID.
So I am trying to get information from a single youtube video via in the JSON format. Like title description category, ect whatever I can get besides the comments. I am trying to do this in Javascript. I noticed the link below but all of their examples are how to get video information from feeds. I would like to get the information from a single video assuming i know its ID.
https://developers.google.com/youtube/2.0/developers_guide_json
我也在看这个 Stackoverflow 问题但我有它说的 get 请求有问题test.js(第 10 行)获取 http://gdata.youtube.com/feeds/api/videos/VA770w...v=2&alt=json-in-script&callback=listInfo
I was also looking at this Stackoverflow Question but I have an issue with the get request it says "test.js (line 10) GET http://gdata.youtube.com/feeds/api/videos/VA770w...v=2&alt=json-in-script&callback=listInfo
200 正常9 毫秒"
200 OK 9ms"
简而言之,如果我有一个像 VA770wpLX-Q 这样的 youtube 视频 ID,那么在 JSON 中获取该视频信息的网址会是什么样的?
谢谢
推荐答案
2015 年 5 月更新:
此解决方案无法正常工作,YouTube API v2 正在处理中,即将停止使用.
This solution doesn't work properly, YouTube API v2 is in process to be discontinued soon.
更多信息请访问:https://www.youtube.com/devicesupport
试试这样的:
var video_id='VA770wpLX-Q';
$.getJSON('http://gdata.youtube.com/feeds/api/videos/'+video_id+'?v=2&alt=jsonc',function(data,status,xhr){
alert(data.data.title);
// data contains the JSON-Object below
});
返回的 JSON 如下所示:
The returned JSON looks like this:
{
"apiVersion": "2.1",
"data": {
"id": "VA770wpLX-Q",
"uploaded": "2011-02-24T22:31:02.000Z",
"updated": "2012-04-08T21:37:06.000Z",
"uploader": "drdrevevo",
"category": "Music",
"title": "Dr. Dre - I Need A Doctor (Explicit) ft. Eminem, Skylar Grey",
"description": "Music video by Dr. Dre performing I Need A Doctor featuring Eminem and Skylar Grey (Explicit). © 2011 Aftermath Records",
"tags": ["Dr", "Dre", "Eminem", "New", "Song", "Skylar", "Grey", "GRAMMYs", "Dr.", "Need", "Doctor", "video", "Eazy", "N.W.A.", "NWA", "easy", "drdre", "and", "em"],
"thumbnail": {
"sqDefault": "http://i.ytimg.com/vi/VA770wpLX-Q/default.jpg",
"hqDefault": "http://i.ytimg.com/vi/VA770wpLX-Q/hqdefault.jpg"
},
"player": {
"default": "http://www.youtube.com/watch?v=VA770wpLX-Q&feature=youtube_gdata_player"
},
"content": {
"5": "http://www.youtube.com/v/VA770wpLX-Q?version=3&f=videos&app=youtube_gdata"
},
"duration": 457,
"aspectRatio": "widescreen",
"rating": 4.902695,
"likeCount": "430519",
"ratingCount": 441253,
"viewCount": 88270796,
"favoriteCount": 306556,
"commentCount": 270597,
"status": {
"value": "restricted",
"reason": "requesterRegion"
},
"restrictions": [{
"type": "country",
"relationship": "deny",
"countries": "DE"
}],
"accessControl": {
"comment": "allowed",
"commentVote": "allowed",
"videoRespond": "allowed",
"rate": "allowed",
"embed": "allowed",
"list": "allowed",
"autoPlay": "denied",
"syndicate": "allowed"
}
}
}
这篇关于在 Javascript 中通过 JSON 获取单个视频(不是提要)的 Youtube 信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!