How to generate download link from any Youtube videos in PHP?
I'm working on a web application that allow users to post any Youtube videos to their profile or pages they manages. This is the code that I use to post Youtube video to my profile
$videoUpload = $fb->post('/me/videos', ['description' => 'example description', 'file_url' => 'https://r2---sn-npoeene7.googlevideo.com/videoplayback?pl=24&lmt=1513082002389285&id=o-AIPnl4v8svvYBTFPYwJOsRanE_5O8YSK0F3bMkTqN6QR&itag=22&signature=8051FCC4C243296224CD1D7ADB4E5C0A90125C57.66FF9FF2063C3A8F00F143FB51BB3E98F7AEBB7B&requiressl=yes&ip=203.189.156.104&sparams=dur,ei,expire,id,initcwndbps,ip,ipbits,itag,lmt,mime,mm,mn,ms,mv,pl,ratebypass,requiressl,source&key=cms1&mime=video%2Fmp4&dur=301.952&fvip=2&ipbits=0&c=WEB&expire=1519648901&ratebypass=yes&ei=JayTWtSaDcWqoQORionoCg&source=youtube&redirect_counter=1&cm2rm=sn-jvbxuxavoapox-2oil7e&fexp=23712580&req_id=21384f45d53ba3ee&cms_redirect=yes&mm=29&mn=sn-npoeene7&ms=rdu&mt=1519627218&mv=m'], $access_token);
$videoUpload = $videoUpload->getGraphNode()->asArray();
The problem is that Facebook not allow to post Youtube link directly, so I need to generate a downloadable link from that video in order to post to Facebook. Here is the PHP code that use to generate a download link from a Youtube video
<?php
$id = 'RllJtOw0USI';
if (isset($_GET["id"]))
$id = $_GET["id"];
parse_str(file_get_contents('http://www.youtube.com/get_video_info?video_id='.$id), $video_data);
$streams = $video_data['url_encoded_fmt_stream_map'];
$streams = explode(',',$streams);
$counter = 1;
foreach ($streams as $streamdata) {
printf("Stream %d:<br/>
It's only work with RllJtOw0USI if I change the $id to dMK_npDG12Q it's not working anymore, and I got the errors as follow:
{-code-3}
How can I get the link from this kind of video?
Answer
Answer
Solution:
If you look at reason in json, you can see that
So you should obey their restrictions, or find any other link which is not restricted yet.