0

我已经下载了一个脚本来将视频上传到 YouTube,它也很完美。

我的问题是,谷歌的参数是什么?什么是仅通过 php 而不是通过表单元素添加视频的正确代码?

前任。

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

这是代码:

<?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" />

希望有人能帮忙!

4

1 回答 1

0

无法上传视频,只能传入视频存储在其他 Web 服务器上的位置的 URL。您需要拥有视频的本地副本,并且需要在上传请求中包含视频的所有字节。所以这是您需要注意的第一件事——制作视频的本地副本。

您应该做的第二件事是使用YouTube GData API的“Zend_Gdata”PHP 客户端库并遵循本开发人员指南中的示例,因为它将大大简化您的代码。

于 2013-06-25T15:54:41.627 回答