1. How to use the API
If you need a channel video, you need to use the YouTube API V3 . Use youtube.search.list
with parameters:
part=id, snippet channelId=ID OF THE CHANNEL order=date type=video
How to find YouTube channel id?
You can find the channel identifier with its channel name http://mpgn.imtqy.com/YTC-ID/
Additional information youtube.search.list right here .
This is a live demonstration .
2. With Javascript?
- First you need to create a project in console.google.developers .
- Enable YouTube API V3 API (Enabled).
- In your account, create a public passkey.
Also, if this is a public application, you might be interested in: How to protect a public API key?
This is the basic code for receiving the video channel:
<!DOCTYPE html> <html> <head> <script src="//code.jquery.com/jquery-2.1.1.min.js"></script> <meta charset="utf-8"> <title>JS Bin</title> </head> <body> <script> function googleApiClientReady() { var apiKey = 'your api key'; gapi.client.setApiKey(apiKey); gapi.client.load('youtube', 'v3', function() { request = gapi.client.youtube.search.list({ part: 'snippet', channelId: 'UCqhNRDQE_fqBDBwsvmT8cTg', order: 'date', type: 'video' }); request.execute(function(response) { console.log(response); }); }); } </script> <script src="https://apis.google.com/js/client.js?onload=googleApiClientReady"></script> </body> </html>
3. With AngularJS?
Using AngularJS, you need to create a Google service, for example, and you can use this service in your controllers.
Example example: https://gist.github.com/jakemmarsh/5809963 You do not need the authentication part. In this case, it is important to use deferred .
An example in the controller
'use strict'; function init() { window.initGapi(); // Calls the init function defined on the window } angular.module('team') .controller('VideosCtrl', function ($scope, $window, $sce, googleService) { $window.initGapi = function() { $scope.$apply($scope.getChannel); }; $scope.getChannel = function () { googleService.googleApiClientReady().then(function (data) { $scope.channel = data; }, function (error) { console.log('Failed: ' + error) }); }; });
GoogleService example
.service('googleService', ['$http', '$q', function ($http, $q) { var deferred = $q.defer(); this.googleApiClientReady = function () { gapi.client.setApiKey('YOU API KEY'); gapi.client.load('youtube', 'v3', function() { var request = gapi.client.youtube.playlistItems.list({ part: 'snippet', playlistId: 'PLila01eYiSBjOtR8oqXkY0i5c1QS6k2Mu', maxResults: 8 }); request.execute(function(response) { deferred.resolve(response.result); }); }); return deferred.promise; }; }])
You need to add this line to your index.html index
<script src="https://apis.google.com/js/client.js?onload=init"></script>
Hope this helps!