<bdo id='MYrwi'></bdo><ul id='MYrwi'></ul>

      <legend id='MYrwi'><style id='MYrwi'><dir id='MYrwi'><q id='MYrwi'></q></dir></style></legend>

        <small id='MYrwi'></small><noframes id='MYrwi'>

        <tfoot id='MYrwi'></tfoot>
      1. <i id='MYrwi'><tr id='MYrwi'><dt id='MYrwi'><q id='MYrwi'><span id='MYrwi'><b id='MYrwi'><form id='MYrwi'><ins id='MYrwi'></ins><ul id='MYrwi'></ul><sub id='MYrwi'></sub></form><legend id='MYrwi'></legend><bdo id='MYrwi'><pre id='MYrwi'><center id='MYrwi'></center></pre></bdo></b><th id='MYrwi'></th></span></q></dt></tr></i><div id='MYrwi'><tfoot id='MYrwi'></tfoot><dl id='MYrwi'><fieldset id='MYrwi'></fieldset></dl></div>

        使用 Youtube Data API V3 和 Google API Client PHP 将视频上传到 Youtub

        时间:2023-10-10

      2. <small id='MsTPN'></small><noframes id='MsTPN'>

      3. <tfoot id='MsTPN'></tfoot>
        • <bdo id='MsTPN'></bdo><ul id='MsTPN'></ul>

          • <legend id='MsTPN'><style id='MsTPN'><dir id='MsTPN'><q id='MsTPN'></q></dir></style></legend>
              <tbody id='MsTPN'></tbody>
            <i id='MsTPN'><tr id='MsTPN'><dt id='MsTPN'><q id='MsTPN'><span id='MsTPN'><b id='MsTPN'><form id='MsTPN'><ins id='MsTPN'></ins><ul id='MsTPN'></ul><sub id='MsTPN'></sub></form><legend id='MsTPN'></legend><bdo id='MsTPN'><pre id='MsTPN'><center id='MsTPN'></center></pre></bdo></b><th id='MsTPN'></th></span></q></dt></tr></i><div id='MsTPN'><tfoot id='MsTPN'></tfoot><dl id='MsTPN'><fieldset id='MsTPN'></fieldset></dl></div>

                  本文介绍了使用 Youtube Data API V3 和 Google API Client PHP 将视频上传到 Youtube -- 收到 401(未经授权)消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我必须实现一种将视频从我们的网站上传到 youtube 的方法.我已经在 Google Cloud 中注册了该应用程序并获得了所有必要的客户端 ID、客户端密码、浏览器密钥、重定向 uri 和服务器密钥.我还按照各种网站的建议启用了 Youtube Data API V3、Google+ API、Freebase API 和 YouTube Analytics API.

                  I have to implement a way to upload video from our site to youtube. I already registered the app in Google Cloud and got all the necessary client ID, client secret code, browser key, redirect uri and server key. I also did turn ON the Youtube Data API V3, Google+ API, Freebase API and YouTube Analytics API as suggessted by various sites.

                  这是我的代码如下:

                      require_once 'google-api-php-client/src/Google_Client.php';
                      require_once 'google-api-php-client/src/contrib/Google_YouTubeService.php';
                  
                      $client = new Google_Client();
                      $client->setApplicationName('Application Name');
                      $client->setClientId('CLIENT_ID');
                      $client->setClientSecret('CLIENT_SECRET_CODE');
                      $client->setRedirectUri('REDIRECT_URI');
                      $client->setDeveloperKey('DEVELOPER_KEY');
                  
                      $youtube = new Google_YouTubeService($client);
                      if (isset($_GET['code'])) {
                          $client->authenticate();
                          $_SESSION['token'] = $client->getAccessToken();
                          $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
                          header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
                      }
                  
                      if (isset($_SESSION['token'])){
                          $client->setAccessToken($_SESSION['token']);
                      }
                  
                      if ($client->getAccessToken()){
                          $path_to_video_to_upload = $_FILES["video"]["tmp_name"];
                          $mime_type = $_FILES["video"]["type"];
                          $snippet = new Google_VideoSnippet();
                          $snippet->setTitle('Highlights');
                          $snippet->setDescription('Description Of Video');
                          $snippet->setTags(array('training', 'Soccer'));
                          $snippet->setCategoryId(17);
                  
                          $status = new Google_VideoStatus();
                          $status->privacyStatus = "private";
                  
                          $video = new Google_Video();
                          $video->setSnippet($snippet);
                          $video->setStatus($status);
                  
                          try {
                              $obj = $youtube->videos->insert("status,snippet", $video,
                              array("data"=>file_get_contents($path_to_video_to_upload), 
                              "mimeType" => $mime_type));
                              } catch(Google_ServiceException $e) {
                              print "Caught Google service Exception ".$e->getCode(). " message is ".$e->getMessage()." <br>";
                              }
                  
                      $_SESSION['token'] = $client->getAccessToken();
                      }
                  
                      else{
                              $authUrl = $client->createAuthUrl();
                              print "<a href='$authUrl'>Connect Me!</a>";
                      }
                  

                  我引用的这些代码来自:使用 Youtube API V3 和 PHP 将视频上传到 Youtube

                  I was referencing these codes from: Upload video to Youtube using Youtube API V3 and PHP

                  http://www.dreu.info/blog/uploading-a-video-to-youtube-through-api-version-3-in-php/

                  我第一次运行此代码时,它让我连接到 youtube 帐户(屏幕上要求让谷歌管理我的 YT 帐户),然后在第二次尝试时,我收到了 401 消息响应.

                  First time I ran this code, it had me connect to the youtube account (with a screen asking to let google manage my YT account) and then on the second try, I got this 401 Message response.

                  这是来自 youtube 服务器的响应

                  Here's the response from youtube server

                  捕获的 Google 服务异常 401 消息是调用 POST 时出错 https://www.googleapis.com/upload/youtube/v3/videos?part=status%2Csnippet&uploadType=multipart&key=AIzaSyCCySI5cToH3sICTmhCEFHW7QkIDptsjXg:(401) 未授权

                  Caught Google service Exception 401 message is Error calling POST https://www.googleapis.com/upload/youtube/v3/videos?part=status%2Csnippet&uploadType=multipart&key=AIzaSyCCySI5cToH3sICTmhCEFHW7QkIDptsjXg: (401) Unauthorized

                  我试图寻找各种解决方案但无济于事,我似乎无法找到它.感谢任何帮助,谢谢!

                  I tried to search for various solutions but to no avail I cant seem to find it. Any help is appreciated, thanks!

                  后续问题:开发者密钥是浏览器密钥还是服务器密钥?我很困惑我应该在我的代码中使用哪个.我试过切换键,它也不起作用.

                  follow-up question: Is the developer key the browser key or the server key? I am confused as to which should I use in my code. I've tried switching the keys and it also didn't work.

                  推荐答案

                  对于那些遇到 Access Not Configured 问题的人.请使用 Google Developers Console 为您的项目激活 API,

                  For Those who are getting the problem of Access Not Configured. Please use Google Developers Console to activate the API for your project,

                  @justine1234 的代码运行良好.删除即可

                  code by @justine1234 is working perfectly fine. Just remove

                  $client->setDeveloperKey('DEVELOPER_KEY');
                  

                  并运行它.

                  非常感谢@justine1234 的代码.

                  Thanks a lot for the code @justine1234.

                  问候

                  这篇关于使用 Youtube Data API V3 和 Google API Client PHP 将视频上传到 Youtube -- 收到 401(未经授权)消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:限制 Laravel 分页显示的链接数量 下一篇:从带有 PHP 的 URL 获取 YouTube 视频 ID

                  相关文章

                1. <tfoot id='q32GO'></tfoot>
                2. <small id='q32GO'></small><noframes id='q32GO'>

                    <legend id='q32GO'><style id='q32GO'><dir id='q32GO'><q id='q32GO'></q></dir></style></legend>
                      <bdo id='q32GO'></bdo><ul id='q32GO'></ul>
                    <i id='q32GO'><tr id='q32GO'><dt id='q32GO'><q id='q32GO'><span id='q32GO'><b id='q32GO'><form id='q32GO'><ins id='q32GO'></ins><ul id='q32GO'></ul><sub id='q32GO'></sub></form><legend id='q32GO'></legend><bdo id='q32GO'><pre id='q32GO'><center id='q32GO'></center></pre></bdo></b><th id='q32GO'></th></span></q></dt></tr></i><div id='q32GO'><tfoot id='q32GO'></tfoot><dl id='q32GO'><fieldset id='q32GO'></fieldset></dl></div>