0

I have downloaded a script to upload videos to YouTube, and it also works perfect.

My question is, what is google's parameters og what is the correctly code to add a video though php only, and not though the form element?

ex.

$videoURL = "Http://myurl.com/video.mp4"; 

Here is the code:

<?php session_start();
set_time_limit(0);
ini_set('memory_limit', '150M');
ini_set('upload_max_filesize', '30M');
ini_set('default_socket_timeout', '6000');
ini_set('max_input_time', '6000');
ini_set('post_max_size', '100M');
ini_set('max_execution_time', '6000');

$accountType = 'HOSTED_OR_GOOGLE';
$youtube_email    = 'xxxx'; //youtube username or gmail account
$youtube_password      = 'xxxxx'; //account password
$source  = urlencode('ps'); //name of application (can be anything) // a short string identifying your application  
$key  = 'AI39si7OKa6-enYv34I7rm68sVaGHeHAK1fhe6UDx0Qh3Z8DEXr9_SBConY4TJ9HO7mLnZVlVl0xoVGPVEjZPMS6mDmdG0WB9g'; //your youtube developer key
$authenticationURL= 'https://www.google.com/youtube/accounts/ClientLogin'; 

$postdata = "Email=".$youtube_email."&Passwd=".$youtube_password."&service=youtube&source=$source";
$curl = curl_init("https://www.google.com/youtube/accounts/ClientLogin");
curl_setopt($curl, CURLOPT_HEADER, "Content-Type:application/x-www-form-urlencoded");
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
$response = curl_exec($curl);
curl_close($curl);


list($auth, $youtubeuser) = explode("\n", $response);
list($authlabel, $authvalue) = array_map("trim", explode("=", $auth));
list($youtubeuserlabel, $youtubeuservalue) = array_map("trim", explode("=", $youtubeuser));

$youtube_video_title = "sdfsdfdf"; // This is the uploading video title.
$youtube_video_description = "sdfdfdfdf"; // This is the uploading video description.
$youtube_video_category = "Film"; // This is the uploading video category.
$youtube_video_keywords = "devil"; // This is the uploading video keywords.


$data = '<?xml version="1.0"?>
        <entry xmlns="http://www.w3.org/2005/Atom"
          xmlns:media="http://search.yahoo.com/mrss/"
          xmlns:yt="http://gdata.youtube.com/schemas/2007">
          <media:group>
            <media:title type="plain">'.$youtube_video_title.'</media:title>
            <media:description type="plain">'.$youtube_video_description.'</media:description>
            <media:category
              scheme="http://gdata.youtube.com/schemas/2007/categories.cat">'.$youtube_video_category.'</media:category>
            <media:keywords>'.$youtube_video_keywords.'</media:keywords>
          </media:group>
        </entry>';


$headers = array("Authorization: GoogleLogin auth=".$authvalue,
             "GData-Version: 2",
             "X-GData-Key: key=".$key,
             "Content-length: ".strlen($data),
             "Content-Type: application/atom+xml; charset=UTF-8");

$curl = curl_init("http://gdata.youtube.com/action/GetUploadToken");
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_REFERER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_HEADER, 0);

$response = simplexml_load_string(curl_exec($curl));
echo $response;
curl_close($curl);


$rUrl = $response->url;
$nexturl = urlencode('http://pointsafari.dk/blablabla.php');
?>

<form action="<?php echo $rUrl; ?>?nexturl=<?php echo $nexturl; ?>" method="post" enctype="multipart/form-data" >
  <input id="file" type="file" name="file"/>
  <div id="errMsg" style="display:none;color:red">
    You need to specify a file.
  </div>
  <input type="hidden" name="token" value="<?php echo($response->token); ?>"/>

   <input type="submit" value="go" />

Hope someone can help!

1

1 Answer 1

0

It's not possible to upload a video and only pass in the URL of the location where the video is stored on some other web server. You need to have a local copy of the video and you need to include all the bytes of the videos in your upload request. So that's the first thing you need to take care of—making a local copy of the video.

The second thing that you should be doing is using the "Zend_Gdata" PHP client library for the YouTube GData API and following the example in this developers guide, as it will greatly simplify your code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.