使用jQuery获取视频的Vimeo缩略图 [英] Get Vimeo thumbnail for video using jQuery

查看:114
本文介绍了使用jQuery获取视频的Vimeo缩略图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了类似的问题,但没有一个答案清楚而轻松地显示如何使用jQuery和JSON获取vimeo视频的缩略图。如果有人可以提供帮助那就太好了,这就是我所拥有的,但它目前没有显示任何内容。

I've found similar questions but none of the answers show clearly and easily how to get a thumbnail for a vimeo video using jQuery and JSON. If anyone can help that would be great, here is what I've got but it shows nothing at the moment.

var vimeoVideoID = '17631561';
var videoCallback = 'showThumb';

$.getJSON('http://www.vimeo.com/api/v2/video/' + vimeoVideoID + '.json?callback=' + videoCallback,

function(data){
$(".thumbs").attr('src',data[0].thumbnail_large);
});

提前致谢。

推荐答案

我相信你有同源政策问题。您应该考虑使用类似 file_get_contents fopen ,使您能够从中获取数据vimeo,将其翻译为json,并通过一个很好的ajax调用输出到你的javascript。

I believe you're having the "same origin policy" issue. You should consider writing a server side script using something like "file_get_contents" or "fopen", enabling you to grab the data from vimeo, translate it to json, and output to your javascript with a nice ajax call.

如果你想避免使用服务器端脚本,你可以使用数据输入JSONP。

If you would like to avoid using a server-side script you may use the data type JSONP.

var vimeoVideoID = '17631561';

$.getJSON('https://www.vimeo.com/api/v2/video/' + vimeoVideoID + '.json?callback=?', {format: "json"}, function(data) {
         $(".thumbs").attr('src', data[0].thumbnail_large);
});

请注意,URL与您使用它的方式略有不同。您定义为var的回调是不必要的。您将getJSON直接附加到函数中,因此您将在url'?'中调用'callback'。这会通知getJSON函数将成功的数据返回传递给提供的函数。

Notice the URL is a bit different from how you are using it. The callback which you defined as a var is unnecessary. You're attaching the getJSON to a function directly, so you'll call the 'callback' in the url '?'. This informs the getJSON function to pass the successful data return to the supplied function.

您可以在此处测试我的代码。希望它有所帮助!

You can test my code here. Hope it helps!

这篇关于使用jQuery获取视频的Vimeo缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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