Vimeo:从API获取下载链接

时间:2016-05-26 16:01:50

标签: c# .net vimeo-api

我有Vimeo PRO,我正在尝试获取下载链接,以便最终用户可以下载视频源。但是,由于缺乏文档,很难弄明白。

我正在尝试VimeoDotNet,但我无法进行身份验证,我正在执行以下操作:

var client = new VimeoClientFactory().GetVimeoClient(key, secret)
var downloadLink = client.GetVideo(video_id).download;

然而,对GetVideo的调用引发了一个错误,说我必须首先进行身份验证,但我不知道如何!

我也尝试过另一个VimeoClient,但它似乎没有实现下载链接部分。

有人可以帮忙吗?或者更好的是,分享一个有效的例子。感谢。

1 个答案:

答案 0 :(得分:2)

2天后我终于能够做到了,我会分享我所做的事情,万一有人需要它。首先,下载此库:

https://github.com/saeedafshari/VimeoDotNet3

在Visual Studio中打开并编译它。它很简单,所以它立即编译。

然后从项目中引用已编译的DLL并执行以下操作:

var VimeoClient3 = Vimeo.VimeoClient.ReAuthorize(_vimeoAccessToken, 
                   _vimeoAppConsumerKey, _vimeoAppClientSecret);

// videoId is the ID of the video as in the public URL (eg, 123874983)
var result = VimeoClient3.Request("/videos/" + videoId, null, "GET");
if (result == null)
{
    throw new Exception("Video not found.");
}
if (result["download"] == null)
{
    throw new Exception("Download link not available.");
}
foreach (var item in (ArrayList)result["download"])
{
    var downloadLinkInfo = item as Dictionary<string, object>;
    if (downloadLinkInfo == null) continue;

    // For example, get the link for SD quality.
    // As of today, Vimeo was returning an HD quality and a 'mobile' one
    // that is for streaming.
    if (string.Equals((downloadLinkInfo["quality"] as string), "sd", StringComparison.InvariantCultureIgnoreCase))
    {
        return downloadLinkInfo["link"] as string;
    }
}