Vimeo API - 按质量获取视频的直接链接(C#)

时间:2018-02-20 13:36:49

标签: json vimeo vimeo-api

我有一个单用户应用程序,

在Vimeo的游乐场,在进行视频/ {id}时,我得到一个包含以下内容的大型JSON结果:

"files": [
        {
            "quality": "hd",
            "type": "video/mp4",
            "width": 1920,
            "height": 1080,
            "link": "...link...",
            "created_time": "2018-02-15T13:46:25+00:00",
            "fps": 23.980000000000000426325641456060111522674560546875,
            "size": 3113207678,
            "md5": "b6beed65b699df870e481045178accc5",
            "link_secure": "...link..."
        },
        {
            "quality": "sd",
            "type": "video/mp4",
            "width": 640,
            "height": 360,
            "link": "...link...",
            "created_time": "2018-02-15T13:46:05+00:00",
            "fps": 23.980000000000000426325641456060111522674560546875,
            "size": 536864946,
            "md5": "af227a5526af15d2bce6ac951d6cf06b",
            "link_secure": "...link..."
        },
        {
            "quality": "sd",
            "type": "video/mp4",
            "width": 960,
            "height": 540,
            "link": "...link...",
            "created_time": "2018-02-15T13:46:05+00:00",
            "fps": 23.980000000000000426325641456060111522674560546875,
            "size": 1242328160,
            "md5": "1963f908509b14fd7a40dc46bfa6c519",
            "link_secure": "...link..."
        },
        {
            "quality": "hd",
            "type": "video/mp4",
            "width": 1280,
            "height": 720,
            "link": "...link...",
            "created_time": "2018-02-15T13:46:05+00:00",
            "fps": 23.980000000000000426325641456060111522674560546875,
            "size": 1977386604,
            "md5": "af38f067bd39f4f5bb71bad72f925337",
            "link_secure": "...link..."
        },
        {
            "quality": "hls",
            "type": "video/mp4",
            "link": "...link...",
            "created_time": "2018-02-15T13:46:25+00:00",
            "fps": 23.980000000000000426325641456060111522674560546875,
            "size": 3113207678,
            "md5": "b6beed65b699df870e481045178accc5",
            "link_secure": "...link..."
        }

(我编辑了网址)

但是在我的代码中执行相同的调用时,整个"文件"部分缺失(整个json结果看起来也不同):

json

这是我的代码,电话:

vc.Request("/videos/255898412", null, "GET");

请求方法:

 public Dictionary<string, object> Request(
            string url,
            Dictionary<string, string> parameters,
            string method,
            bool jsonBody = true)
        { 
            var headers = new WebHeaderCollection()
            {
                { "Authorization", String.Format("Bearer {0}", AccessToken) }
            };
            method = method.ToUpper();
            url = apiRoot + url;
            string body = "";
            string contentType = "application/x-www-form-urlencoded";

            if (parameters != null && parameters.Count > 0)
            {
                if (method == "GET")
                {
                    url += "?" + Helpers.KeyValueToString(parameters);
                }
                else if (method == "POST" || method == "PATCH" || method == "PUT" || method == "DELETE")
                {
                    if (jsonBody)
                    {
                        contentType = "application/json";
                        body = jsonEncode(parameters);
                    }
                    else
                    {
                        body = Helpers.KeyValueToString(parameters);
                    }
                }
            }


            return  JsonConvert.DeserializeObject<Dictionary<string, object>>(Helpers.HTTPFetch(url, method, headers, body, contentType));

        }

我的目标是获取HLS直接链接,在我的播放器中播放。 我怎样才能实现它?

由于

2 个答案:

答案 0 :(得分:1)

我今天也遇到了同样的问题。

我的愚蠢解决方案如下。

  • 使用3.1版API

答案 1 :(得分:1)

有一个错误,使用API​​ v3.4没有为devs返回下载和文件密钥。 Vimeo已修复该错误(截至2014年2月23日)。

从API v3.4开始,开发人员必须使用具有video_files范围的令牌对请求进行身份验证,以便在视频响应中接收下载和文件密钥。

如果您使用OAuth工作流生成令牌,则可以使用video_files范围生成令牌:https://developer.vimeo.com/api/authentication#supported-scopes

我希望这些信息有所帮助!