【问题标题】:YouTube API v3 authenticate user and then get his videosYouTube API v3 对用户进行身份验证,然后获取他的视频
【发布时间】:2015-07-24 12:44:30
【问题描述】:

我是使用 youtube API 的新手, 在我的网站中,我允许用户上传他们的视频,我想使用 youtube api 添加一个新功能,允许用户从他们的 youtube 频道上传他们的视频。

场景:

  1. 用户将使用他的 google 帐户登录
  2. 我会得到他的 youtube 用户名或频道 ID
  3. 然后我会从频道 ID 或用户名中获取视频 ID
  4. 然后我会列出他的视频,他可以选择他想要的 上传

这是我下面的代码,它工作正常,我想要的步骤是与用户进行身份验证并获取他的用户名或频道 ID

$(document).ready(function () {

  var channelName = 'PochicaKing';

  $.get(
          "https://www.googleapis.com/youtube/v3/channels", {
            part: 'contentDetails',
            forUsername: channelName,
//            mine: true,
//            access_token: 'ya29.cQEoJbvUmAMT6xJFgDoi4gq0EW8O5Q_9ZqLtNUay0AbNh-mldmNh5mlicarLx00AHxL_O6Vur8M3Bw',
            key: 'AIzaSyARSqGexKgNt0BdHUJBXg2pnxMGgYXrszw'
          },
  function (data) {

    $.each(data.items, function (i, item) {
      console.log(item);
      pid = item.contentDetails.relatedPlaylists.likes;
      gitVids(pid);
    });

  }
  );

  function gitVids(pid) {

    $.get(
            "https://www.googleapis.com/youtube/v3/playlistItems", {
              part: 'snippet',
              maxResults: 5,
              playlistId: pid,
              key: 'AIzaSyARSqGexKgNt0BdHUJBXg2pnxMGgYXrszw'
            },
    function (data) {

      var output;
      $.each(data.items, function (i, item) {
//      console.log(item);
        vidTitle = item.snippet.title;
        vidId = item.snippet.resourceId.videoId;

        output = '<li><iframe width="420" height="315"src="http://www.youtube.com/embed/' + vidId + '"></iframe></li>'
        $('#results').append(output);
      });

    }
    );



  }





});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<html>
  <head>
    <script src="jquery.min.js" type="text/javascript"></script>
    <script src="script.js" type="text/javascript"></script>
    
  </head>
  <body>
    <ul id="results"></ul>
  </body>
</html>

【问题讨论】:

    标签: javascript php api youtube youtube-api


    【解决方案1】:

    我找到了,通过这个样本 https://github.com/youtube/api-samples 对于 php

    如果您下载了它,它将无法工作,因为它需要在“Src/Google”中的另一个文件夹“Google” 这里 https://github.com/google/google-api-php-client/tree/master/src/Google

    您还需要在文件中包含“autoload.php”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-12
      • 2015-01-03
      • 2013-10-27
      • 1970-01-01
      • 2015-04-05
      • 2014-05-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多