Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php从twitter获取视频_Php_Video_Twitter - Fatal编程技术网

使用php从twitter获取视频

使用php从twitter获取视频,php,video,twitter,Php,Video,Twitter,我已经找了一段时间了,是时候问问了。如何在我的定制php提要中获取twitter视频。我可以把照片上传到URL,使用类似..的东西没问题 $tweet->entities->media[0]->media_url; 但是我找不到一个解决方案来获取用户提要视频url,甚至连视频的海报图像url也很好。在搜索时使用“过滤器=视频” 示例调用可以是: ?q=#dog&result_type=recent&count=20&filter=videos&

我已经找了一段时间了,是时候问问了。如何在我的定制php提要中获取twitter视频。我可以把照片上传到URL,使用类似..的东西没问题

$tweet->entities->media[0]->media_url;

但是我找不到一个解决方案来获取用户提要视频url,甚至连视频的海报图像url也很好。

在搜索时使用“过滤器=视频” 示例调用可以是:

?q=#dog&result_type=recent&count=20&filter=videos&include_entities=true
视频url: 请参见下面的回复:

[urls] => Array
(
    [0] => stdClass Object
        (
            [url] => https://t.co/u9Yaulk7Nz
            [expanded_url] => https://vine.co/v/O2T90LHOwV6
            [display_url] => vine.co/v/O2T90LHOwV6
            [indices] => Array
                (
                    [0] => 97
                    [1] => 120
                )

        )

)
HTML示例

<a href="https://vine.co/v/O2T90LHOwV6"><img src="http://pbs.twimg.com/ext_tw_video_thumb/571566115719004160/pu/img/H8GR0a02w_vAzUjr.jpg:thumb"></a>


我希望这会有所帮助。

假设您有一条tweet是使用保存在$tweet中的搜索/tweets获取的

// Check if tweet has media
if (!empty($tweet->entities->media)) {
    $searchArray = array(
        "id" => $tweet->id, // id of the tweet we just fetched
        "include_entities" => true // tells twitter API to return videos and stuff
    );

    // Get extended_entities
    $extendedEntities = $connection->get("statuses/show", $searchArray);
    foreach($extendedEntities->extended_entities->media as $media){
        var_dump($media->video_info->variants);
    }
}
array (size=6)
  0 => 
    object(stdClass)[265]
      public 'bitrate' => int 832000
      public 'content_type' => string 'video/webm' (length=10)
      public 'url' => string 'https://video.twimg.com/ext_tw_video/560049056895209473/pu/vid/480x480/gj_fzyk29R9dMPBY.webm' (length=92)
  1 => 
    object(stdClass)[266]
      public 'bitrate' => int 832000
      public 'content_type' => string 'video/mp4' (length=9)
      public 'url' => string 'https://video.twimg.com/ext_tw_video/560049056895209473/pu/vid/480x480/gj_fzyk29R9dMPBY.mp4' (length=91)
  2 => 
    object(stdClass)[267]
      public 'bitrate' => int 1280000
      public 'content_type' => string 'video/mp4' (length=9)
      public 'url' => string 'https://video.twimg.com/ext_tw_video/560049056895209473/pu/vid/720x720/S7F4BF2wKR2txCpA.mp4' (length=91)
  3 => 
    object(stdClass)[268]
      public 'content_type' => string 'application/dash+xml' (length=20)
      public 'url' => string 'https://video.twimg.com/ext_tw_video/560049056895209473/pu/pl/udxtIM8FytsAE4HQ.mpd' (length=82)
  4 => 
    object(stdClass)[269]
      public 'bitrate' => int 320000
      public 'content_type' => string 'video/mp4' (length=9)
      public 'url' => string 'https://video.twimg.com/ext_tw_video/560049056895209473/pu/vid/240x240/v5jqpUNnkaeuVZbx.mp4' (length=91)
  5 => 
    object(stdClass)[270]
      public 'content_type' => string 'application/x-mpegURL' (length=21)
      public 'url' => string 'https://video.twimg.com/ext_tw_video/560049056895209473/pu/pl/udxtIM8FytsAE4HQ.m3u8' (length=83)
示例结果

// Check if tweet has media
if (!empty($tweet->entities->media)) {
    $searchArray = array(
        "id" => $tweet->id, // id of the tweet we just fetched
        "include_entities" => true // tells twitter API to return videos and stuff
    );

    // Get extended_entities
    $extendedEntities = $connection->get("statuses/show", $searchArray);
    foreach($extendedEntities->extended_entities->media as $media){
        var_dump($media->video_info->variants);
    }
}
array (size=6)
  0 => 
    object(stdClass)[265]
      public 'bitrate' => int 832000
      public 'content_type' => string 'video/webm' (length=10)
      public 'url' => string 'https://video.twimg.com/ext_tw_video/560049056895209473/pu/vid/480x480/gj_fzyk29R9dMPBY.webm' (length=92)
  1 => 
    object(stdClass)[266]
      public 'bitrate' => int 832000
      public 'content_type' => string 'video/mp4' (length=9)
      public 'url' => string 'https://video.twimg.com/ext_tw_video/560049056895209473/pu/vid/480x480/gj_fzyk29R9dMPBY.mp4' (length=91)
  2 => 
    object(stdClass)[267]
      public 'bitrate' => int 1280000
      public 'content_type' => string 'video/mp4' (length=9)
      public 'url' => string 'https://video.twimg.com/ext_tw_video/560049056895209473/pu/vid/720x720/S7F4BF2wKR2txCpA.mp4' (length=91)
  3 => 
    object(stdClass)[268]
      public 'content_type' => string 'application/dash+xml' (length=20)
      public 'url' => string 'https://video.twimg.com/ext_tw_video/560049056895209473/pu/pl/udxtIM8FytsAE4HQ.mpd' (length=82)
  4 => 
    object(stdClass)[269]
      public 'bitrate' => int 320000
      public 'content_type' => string 'video/mp4' (length=9)
      public 'url' => string 'https://video.twimg.com/ext_tw_video/560049056895209473/pu/vid/240x240/v5jqpUNnkaeuVZbx.mp4' (length=91)
  5 => 
    object(stdClass)[270]
      public 'content_type' => string 'application/x-mpegURL' (length=21)
      public 'url' => string 'https://video.twimg.com/ext_tw_video/560049056895209473/pu/pl/udxtIM8FytsAE4HQ.m3u8' (length=83)