Link to home
Start Free TrialLog in
Avatar of RayT
RayTFlag for United States of America

asked on

YouTube Data API

I have to convert my working v2 code and now I can't seem to get this to work.

I'm trying to retrieve all videos from a selected YouTube channel.  What is wrong with the following code?

var YouTube = {
    LoadVideos: function (channelName, apiKey, maxNumberOfVideos) {
        $(document).ready(function () {
            $.get("https://www.googlesapis.com/youtube/v3/channels", {
                part: "contentDetails",
                forUserName: channelName,
                key: apiKey},
                function (data) {
                    $.each(data.items, function (i, item) {
                        pid = item.contentDetails.relatedPlaylists.uploads;
                        getVideos(pid, apiKey, maxNumberOfVideos);
                    })
                }
        );
        });
    },

    getVideos: function (pid, apiKey, maxNumberOfVideos) {
        $.get("https://www.googlesapis.com/youtube/v3/playlistItems", {
            part: "snippet",
            maxResults: maxNumberOfVideos,
            playlistId: pid,
            key: apiKey},
            function (data) {
                $.each(data.items, function (i, item) {
                })
            }
        );
    },

    PlayVideo: function (url, width, height) {
        $('#ytplayer').attr('src', url);
        $('#ytplayer').attr('width', width);
        $('#ytplayer').attr('height', height);
    }
}

Open in new window

SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RayT

ASKER

Thanks!