加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 将文件从实时服务器上传到youtube不起作用?

发布时间:2020-12-13 22:47:54 所属栏目:PHP教程 来源:网络整理
导读:我正在进行管道API集成.这个代码在本地主机上工作得很好.但是它不能正常工作.它不能将视频从实时服务器上传到YouTube.我无法从我的实时服务器上传YouTube上的视频.我我试图解决近2天的问题.这是上传视频到YouTube的示例代码. ?php $youtube_email = "xxxxxxx
我正在进行管道API集成.这个代码在本地主机上工作得很好.但是它不能正常工作.它不能将视频从实时服务器上传到YouTube.我无法从我的实时服务器上传YouTube上的视频.我我试图解决近2天的问题.这是上传视频到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,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",$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,true);
    curl_setopt($curl,CURLOPT_TIMEOUT,10);
    curl_setopt($curl,false);
    curl_setopt($curl,CURLOPT_FOLLOWLOCATION,CURLOPT_HTTPHEADER,$headers);
    curl_setopt($curl,$data);
    curl_setopt($curl,CURLOPT_REFERER,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>

请为此提供近似解决方案….尽快…

解决方法

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

你正在传递<?php echo(urlencode($nexturl)); ?>作为那里的值,所以如果你在上传完成后得到一个页面未找到响应,那是因为该值. 看看你的代码,我认为问题是你的$nexturl值是“http://www.walola.com”,它已经被URL转义,然后你在它上面调用urlencode().尝试使用“http://www.walola.com”代替$nexturl,然后调用urlencode().

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读