如何获得Vine视频标题/描述?

时间:2013-06-21 06:50:48

标签: php api video twitter vine

以下是藤蔓视频示例https://vine.co/v/bjHh0zHdgZT。我怎样才能得到它的描述?

假设我有视频的id是bjHh0zHdgZT,我需要获得基于PHP的网站的藤蔓描述。

感谢。

1 个答案:

答案 0 :(得分:1)

也许你可以解析页面的元标记?

葡萄藤页面来源:

<meta property="twitter:card" content="player">
<meta property="twitter:title" content="Jethro Ames's post on Vine">
<meta property="twitter:description" content="SquareVine 1 #howto #favthings #loop">

使用file_get_contents和preg_match:

从php获取描述
<?php
    $url = "https://vine.co/v/bjHh0zHdgZT";
    $data = file_get_contents($url);
    preg_match('~<\s*meta\s+property="(twitter:description)"\s+content="([^"]*)~i', $data, $matches);
    print_r($matches);
    if ( isset($matches[2]) ) {
       $description = $matches[2];
    }
?>

输出:

Array
(
 [0] => <meta property="twitter:description" content="SquareVine 1 #howto #favthings #loop
 [1] => twitter:description
 [2] => SquareVine 1 #howto #favthings #loop
)

您的描述是$ matches [2]。小心控制这个内容(html实体,sql转义等)

相关问题