Youtube API receives unregistered videos

for the project, I have to list all the videos from the youtube user account. I get all the public videos, but when I make an api call after oauth, I only get the public videos anyway.

Private videos are videos that are hidden from the search engine and the user's public page. I am sure there is a way to get this.

Here is my code

var request = gapi.client.youtube.playlistItems.list({
            playlistId: listId,
            part: 'snippet,status',
            maxResults: 25,
            pageToken: nextPageToken
        });

        request.execute(function(response) {
            console.log(response)
            nextPageToken = response.nextPageToken
            if ('error' in response) {
                displayMessage(response.error.message);
            } else {
                if ('items' in response) {
                    console.log(response.items)

                    var a = [];
                    for(var i in response.items){

                        var d = {
                            title: response.items[i].snippet.title,
                            videoId: response.items[i].snippet.resourceId.videoId,
                            publishedAt: response.items[i].snippet.publishedAt
                        }
                        a.push(d);

                        $("#message").append(JSON.stringify(d))
                    }



                } else {
                    displayMessage('There are no videos in your channel.');
                }
            }
        });
+5
source share
3 answers

, YouTube , , , API, YouTube; . - (API -), "" API playlistItems.list.

+2

, forMine = true type = video. Oauth 2.

0

, OAuth, API, , . :

https://console.developers.google.com API API Youtube v3. API, OAuth ClientId. API : "AISdkJKdk7GuSkDKJDKSkLmSSdDFm4ro4E_4et_ww"

# Google.Apis.YouTube.v3 1.40.2.1593 Nuget. , .

You Tube "Unlisted Videos, API" ( YouTube, , , . )

. , , , , , .

, , , . URL, , & list, . : https://www.youtube.com/watch?v=kskScbSkdSDg&list=DKfiVi8sZdkZqW-saZt7bN8DDTDxshjDK. (PlalistId) - DKfiVi8sZdkZqW-saZt7bN8DDTDxshjDK, GetPlaylistVideos.

. :

    public static List<YouTubeVideo> GetPlaylistVideos(string PlaylistId)
    {
        List<YouTubeVideo> result = new List<YouTubeVideo>();

        try
        {
            YouTubeService service = new YouTubeService(new BaseClientService.Initializer()
            {
                ApplicationName = YOUTUBE_APPLICATION_NAME,
                ApiKey = YOUTUBE_API_KEY
            });

            var nextPageToken = "";
            while (nextPageToken != null)
            {
                var playlistItemsListRequest = service.PlaylistItems.List("snippet");
                playlistItemsListRequest.PlaylistId = PlaylistId;
                playlistItemsListRequest.MaxResults = 50;
                playlistItemsListRequest.PageToken = nextPageToken;

                // Retrieve the list of videos uploaded to the authenticated user channel.
                var playlistItemsListResponse = playlistItemsListRequest.Execute();

                foreach (var playlistItem in playlistItemsListResponse.Items)
                {

                    YouTubeVideo v = new YouTubeVideo
                    {
                        EmbedUrl = String.Format("https://www.youtube.com/embed/{0}", playlistItem.Snippet.ResourceId.VideoId),
                        Title = playlistItem.Snippet.Title,
                        Description = playlistItem.Snippet.Description,
                        ThumbnailUrl = playlistItem.Snippet.Thumbnails.High.Url
                    };

                    result.Add(v);
                }

                nextPageToken = playlistItemsListResponse.NextPageToken;
            }

        }

If you call GetPlaylistVideos, you will see that it returns unregistered videos from your unregistered playlist using the API key, not OAuth.

0
source

Source: https://habr.com/ru/post/1606386/


All Articles