YouTube Api视频上传代码无效

时间:2015-10-01 09:01:34

标签: php youtube-api youtube-data-api

我找到了一个代码,用于在我自己的频道上在youtube上上传视频,但是它显示了一些错误..有助于找到我尝试解决这个问题的所有事情......

      <?php

       $youtube_email = "email"; // Change this to your youtube sign in         email.
      $youtube_password = "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);
            print_r($response);
            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 = "Example"; // This is the uploading video title.
            $youtube_video_description = "Example"; // This is the uploading video description.
            $youtube_video_category = "News"; // This is the uploading video category.
            $youtube_video_keywords = "example, 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 = "apikey"; // 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));
            print_r($response);
            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://localhost/youtube.php"; // 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>

但是它显示了一些错误

        Error=BadAuthentication Url=https://www.google.com/accounts/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbuh0dduQUt6wddYfCPGzt13_2yHJDHeRIjGmBk9J6Fpou-BfaoCRULdEWuHxbUZmrBzvQhw0obSD9bQwUEUazXQT33PdBPtWLO0RxIe9gST-vdrwi7sValAtw1AX3x5TE_56TosAb32oOhY4kXHNDAIRE_gd8IZAwigT2mAjr47IaISoBWmNZyYSepTNApJVeLwN7_HQqUwSnU0avOUqfO3DZKwgZAfXKKdQn5jYym6B_-dLHc Info=WebLoginRequired 

      SimpleXMLElement Object ( [error] => SimpleXMLElement Object ( [domain] => yt:authentication [code] => Unknown ) ) 

我已经尝试了其他一些但是他们工作了一段时间或一段时间没有并在用户频道上传视频......

我在等待建议..

0 个答案:

没有答案