Search code examples
youtubeyoutube-apiyoutube-data-api

About Youtube channels and YouTube API v3


I was wondering why is that that some channels return an array in the following code and other don't? I'm trying to make a video gallery but the specific channel won't return me that array that has contentDetails. I also have access to the youtube account if I need to change any settings in there to allow this code to work. I also already have api credentials and added API v3 to the project.

$(document).ready(function() {
    $.get("https://www.googleapis.com/youtube/v3/channels", {
            part: 'contentDetails',
            forUsername: channelName,
            key: 'myKeyvalue'},
            function(data) {
                console.log(data);
                //upload_id = data.items[0].contentDetails.relatedPlaylists.uploads;
            }
    )
}

Thanks in advance.

The data object should contain an array.


Solution

  • That behaviour might be due the channelName value is different from the common/public name.

    Example:

    If you want to check the channel Markiplier, for search this channel using the channels.list endpoint, you have to use the value markiplierGAME as value in the forUsername field.

    So, as alternative you have to get the correct value for the forUsername field or, use the id - in this case, the channel_id.