iam a new in using youtube api , in my website i allow users to upload their videos , i want to add a new feature using youtube api that allow users to upload their videos from their youtube channel .

The scenario: 1- the user will login with his google account 2- i will get his youtube username or channel id 3-then i will get videos IDs from channel id or username 4- then i will list his videos , and he can choose what he want to uplaod

this is my code it is working ok , the step that i want is the authentication with user and get his username or channel 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>

1 Answers

0
Mohamed Osama Gbril On Best Solutions

I found it , by this samples https://github.com/youtube/api-samples for php

if you downloaded it , it will not work because it need another folder "Google" in "Src/Google" here https://github.com/google/google-api-php-client/tree/master/src/Google

also you need to include "autoload.php" in your file