Php:如何在我的vimeo帐户中获取视频网址

时间:2017-11-20 13:36:43

标签: vimeo vimeo-api

我有一个vimeo api密钥,我上传了这个网址https://vimeo.com的视频,并通过此链接https://vimeo.com/home/myvideos获取了我的所有视频链接。现在我收到了所有视频链接详情的回复。

<?php
    $urls   = array();
    $videos = array();
    // vimeo test
    $urls[] = 'https://vimeo.com/243625359';
    $urls[] = 'https://vimeo.com/243438242';

    foreach ($urls as $url) {
    $videos[] = getVideoDetails($url);
    }
    function getVideoDetails($url)
    {
    $host = explode('.', str_replace('www.', '', strtolower(parse_url($url, PHP_URL_HOST))));
    $host = isset($host[0]) ? $host[0] : $host;
    switch ($host) {
    case 'vimeo':
    $video_id = substr(parse_url($url, PHP_URL_PATH), 1);
    $hash = json_decode(file_get_contents("http://vimeo.com/api/v2/video/{$video_id}.json"));
    // header("Content-Type: text/plain");
    // print_r($hash);
    // exit;
    return array(
    'provider'          => 'Vimeo',
    'title'             => $hash[0]->title,
    'description'       => str_replace(array("<br>", "<br/>", "<br />"), NULL, $hash[0]->description),
    'description_nl2br' => str_replace(array("\n", "\r", "\r\n", "\n\r"), NULL, $hash[0]->description),
    'thumbnail'         => $hash[0]->thumbnail_large,
    'video'             => "https://vimeo.com/" . $hash[0]->id,
    'embed_video'       => "https://player.vimeo.com/video/" . $hash[0]->id,
    );
    break;

    }
    }
    header("Content-Type: text/plain");
    print_r($videos);

响应:

 Array
   (
   [0] => Array
    (
        [provider] => Vimeo
        [title] => SampleVideo_1280x720_10mb
        [description] => Vimeo was born in 2004, created by a group of 
        filmmakers who wanted an easy and beautiful way to share videos with 
        their friends. Word started to spread, and an insanely supportive 
        community of creators began to blossom. Now Vimeo is home to more 
        than:
        [description_nl2br] => Vimeo was born in 2004, created by a group of 
             filmmakers who wanted an easy and beautiful way to share videos 
         with their friends. Word started to spread, and an insanely 
        supportive community of creators began to blossom. Now Vimeo is home 
         to more than:
        [thumbnail] => http://i.vimeocdn.com/video/667808655_640.jpg
        [video] => https://vimeo.com/243625359
        [embed_video] => https://player.vimeo.com/video/243625359
    )

[1] => Array
    (
        [provider] => Vimeo
        [title] => SampleVideo_1280x720_5mb
        [description] => We spend our days building a product we love for a growing community of millions. And eating lots of free snacks.
        [description_nl2br] => We spend our days building a product we love for a growing community of millions. And eating lots of free snacks.
        [thumbnail] => http://i.vimeocdn.com/video/667575091_640.jpg
        [video] => https://vimeo.com/243438242
        [embed_video] => https://player.vimeo.com/video/243438242
    )

很好。我手动应用了我的视频链接,但正确的方式来应用我的动态视频链接。我想在基于API的密钥中获取我的vimeo视频网址。

1 个答案:

答案 0 :(得分:0)

您似乎正在使用Vimeo不再支持的旧简单API(使用此网址格式:http://vimeo.com/api/v2/video/{$video_id}.json)。

也就是说,如果您的视频是可嵌入的,那​​么使用oEmbed来获取指定的元数据(提供者,标题,说明,缩略图,视频)可能会更好。 Vimeo的oEmbed文档可在此处找到:https://developer.vimeo.com/apis/oembed

关于您正在生成的videoembed_video值,最佳做法是从API获取视频链接和嵌入代码。由于您自己生成这些值,因此我们对网址结构所做的任何更改都可能会破坏您的链接。例如,未列出的视频在您的代码未考虑的数字video_id之后有一个额外的哈希值。

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