2013-03-07 26 views
4

我工作在你管API的integration.This代码在本地host.But完美工作,但它不工作的现场服务器。进一步它没有上传视频从现场服务器到YouTube.I无法上传视频从我的实时服务器上的YouTube上。我试图解决近2天..这是上传视频到YouTube的示例代码。将文件从活动服务器上传到YouTube不起作用?

<?php 
    $youtube_email = "xxxxxxxx"; // Change this to your youtube sign in email. 
    $youtube_password = "xxxxxxxxx"; // Change this to your youtube sign in password. 

    $postdata = "Email=".$youtube_email."&Passwd=".$youtube_password."&service=youtube&source=Example"; 
    $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 = "kamal"; // This is the uploading video title. 
    $youtube_video_description = "kamal"; // This is the uploading video description. 
    $youtube_video_category = "News"; // This is the uploading video category. 
    $youtube_video_keywords = "kamal, video"; // 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>'; 

    $key = "XXXXXXXXXXXXXXXXXXX"; // Get your key here: http://code.google.com/apis/youtube/dashboard/. 

    $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)); 
    curl_close($curl); 
    ?> 
    <script type="text/javascript"> 
     function checkForFile() { 
     if (document.getElementById('file').value) { 
      return true; 
     } 
     document.getElementById('errMsg').style.display = ''; 
     return false; 
     } 
    </script> 

    <?php 
    $nexturl = "http%3A%2F%2Fwww.walola.com"; // This parameter specifies the URL to which YouTube will redirect the user's browser when the user uploads his video file. 
    ?> 

    <form action="<?php echo($response->url); ?>?nexturl=<?php echo(urlencode($nexturl)); ?>" method="post" enctype="multipart/form-data" onsubmit="return checkForFile();"> 
     <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" /> 

    </form> 
    </php> 

请为此提供近似解....尽快...

+1

本地服务器配置文件和活动配置文件有任何区别吗?当您尝试上传视频时,究竟附加了什么内容? – JoDev 2013-03-07 14:55:23

+0

本地主机和服务器上的Curl和PHP版本是什么?你是否在[通过curl连接youtube?](http://stackoverflow.com/q/15270967/367456)中得到相同的错误信息 - btw你会得到哪个错误信息? – hakre 2013-03-07 16:23:23

+0

嗨hakre ..在本地主机上的视频上传成功在浏览器url上生成管道代码,但活服务器返回页面未找到错误 – krishna 2013-03-08 04:23:40

回答

1

基于浏览器的上传完成由你传递作为该nexturl=参数的URL确定后的加载页面action表单的属性,如documentation中所述。

你传递的是<?php echo(urlencode($nexturl)); ?>作为值,所以如果你在上传完成时得到一个没有找到响应的页面,那是因为那个值。

看着你的代码,我认为问题在于你的$nexturl的值是“http%3A%2F%2Fwww.walola.com”,它已经被URL转义了,然后你打电话给urlencode()就可以了。尝试使用“http://www.walola.com”代替$nexturl,然后在该代码上调用urlencode()

相关问题