使用youtube api通过jQuery获取youtubevideo的标题

从youtybevideo中获取标题的最简单方法是什么,例如此video标题:

http://www.youtube.com/watch?v=Wp7B81Kx66o

谢谢 !

使用jQuery对YouTube API 的JSON调用来获取结果,然后使用jQuery将结果放在您想要的位置。 您可以使用firebug的NET选项卡确保请求/ respoonses正确返回,然后使用console.log()确保正确解析响应。

例如。 url:

获取https://gdata.youtube.com/feeds/api/videos/(the-video-id)?v=2&alt=json

更多信息:

适用于特定video的YouTube API

开发人员指南:JSON / JavaScript

这是@easement使用当前v3 YouTube Data API提供的原始答案的彻底修改。

为了向API发出请求,您可以使用jQuery的getJSON()调用通过AJAX从YouTube请求标题。 YouTube的v3 Data API提供了3个可用于获取标题的端点:

  1. 片段标题 – video的标题。 属性值的最大长度为100个字符,可以包含除<和>之外的所有有效UTF-8字符。
  2. Snippet Localized Title – 本地化video标题,同样具有上述最大长度
  3. 完全本地化标题 – 全长本地化video标题。

使用Snippet Title实现示例

var yt_api_key = {your YouTube api key}, yt_video_id = {your YouTube video id}, yt_snippet_endpoint = "https://www.googleapis.com/youtube/v3/videos?part=snippet&id=" + yt_video_id + "&key=" + yt_api_key; var jqxhr = $.getJSON(yt_snippet_endpoint) .done(function(data) { console.log("second success callback"); var title = getTitle(data); // do something with title here }) .fail(function() { console.log("error, see network tab for response details"); }); function getTitle(snippet_json_data){ var title = snippet_json_data.title; return title; } 

试试这个:

  

这在你的身体部位:

  

试试这个在Jquery列表视图前面显示Youtubefunction图。