2017-11-20 7 views
0

私はvimeo APIキーを持っていて、私はこのURLをhttps://vimeo.comのビデオにアップロードし、このリンクからすべてのビデオリンクを取得してください。https://vimeo.com/home/myvideos今私はすべての私のビデオリンクの詳細のための応答を得ました。php:私のvimeoアカウントでビデオURLを取得する方法

<?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ビデオURLを取得したい。

答えて

0

Vimeoではサポートされていない古いSimple API(このURL形式:http://vimeo.com/api/v2/video/{$video_id}.json)を使用しているようです。

動画が埋め込み可能な場合は、oEmbedを使用して指定したメタデータ(プロバイダ、タイトル、説明、サムネイル、動画)を取得する方がよいでしょう。 Vimeoの者のoEmbedのドキュメントがここに発見された:あなたが作成しているvideoembed_video値についてhttps://developer.vimeo.com/apis/oembed

を、それが正確にAPIからビデオリンクや埋め込みコードを取得することがベストプラクティスです。これらの値を独自に生成しているため、URL構造を変更するとリンクが壊れる可能性があります。たとえば、非公開の動画では、コードで指定されていない数値のvideo_idの後にハッシュが追加されます。

この情報が役立ちますようお願いいたします。

関連する問題