【问题标题】:Php: how to get video urls in my vimeo accountPhp:如何在我的 vimeo 帐户中获取视频网址
【发布时间】:2018-05-03 18:01:12
【问题描述】:

我有一个 vimeo api 密钥,我上传了这个 url 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 视频网址。

【问题讨论】:

    标签: vimeo vimeo-api


    【解决方案1】:

    看来您正在使用 Vimeo 不再支持的旧版 Simple API(网址格式为:http://vimeo.com/api/v2/video/{$video_id}.json)。

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

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

    希望这些信息对您有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-21
      • 1970-01-01
      • 2015-07-22
      • 1970-01-01
      • 2023-04-03
      • 2013-01-11
      • 1970-01-01
      相关资源
      最近更新 更多