php - Get twitter video mp4 url
Get the solution ↓↓↓Solution:
Twitter staff has stated here that they won't be supporting fetching videos using search. You will have to fetch videos with an other call to the API.
Let's say you have a tweet fetched using search/tweets saved in $tweet
// 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);
}
}
Example result
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)
Answer
Solution:
Add the optiontweet_mode:'extended'
to get the extended_entities object in the response.
This path in the response will have video urls :extended_entities.media[0].video_info.variants
Example:
[
{
content_type: 'application/x-mpegURL',
url: 'https://video.twimg.com/ext_tw_video/1358226.........'
},
{
bitrate: 832000,
content_type: 'video/mp4',
url: 'https://video.twimg.com/ext_tw_video/1358226.........'
},
{
bitrate: 256000,
content_type: 'video/mp4',
url: 'https://video.twimg.com/ext_tw_video/1358226.........'
}
]
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: your system folder path does not appear to be set correctly. please open the following file and correct this: index.php
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.