API Youtube / v3 / search не возвращает результаты в. NET - PullRequest
0 голосов
/ 04 августа 2020

Это мой первый опыт использования api поиска YouTube v3, поэтому у меня есть несколько вопросов и некоторый код, на который стоит посмотреть.

Моя основная проблема c на этом этапе заключается в том, что я работаю с образец кода, предоставленный Google, и я не получаю никаких результатов. Приложение зависает:

// Call the search.list method to retrieve results matching the specified query term.
var searchListResponse = await searchListRequest.ExecuteAsync();

Вот мой пример кода:

using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;

using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using Google.Apis.Upload;
using Google.Apis.Util.Store;
using Google.Apis.YouTube.v3;
using Google.Apis.YouTube.v3.Data;

using CPCommon;

namespace CPDataLayer
{
    public class YouTubeSearch : DataLayerBase
    {

        /// <summary>
        /// YouTube Data API v3 sample: search by keyword.
        /// Relies on the Google APIs Client Library for .NET, v1.7.0 or higher.
        /// See https://developers.google.com/api-client-library/dotnet/get_started
        ///
        /// Set ApiKey to the API key value from the APIs & auth > Registered apps tab of
        ///   https://cloud.google.com/console
        /// Please ensure that you have enabled the YouTube Data API for your project.
        /// </summary>
        public void TakedownTargetSearch()
        {
            try
            {
                Run().Wait();
            }
            catch (AggregateException ex)
            {
                foreach (var e in ex.InnerExceptions)
                {
                    Console.WriteLine("Error: " + e.Message);
                }
            }

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }

        private async Task Run()
        {
            var youtubeService = new YouTubeService(new BaseClientService.Initializer()
            {
                // I x'ed out our api key.
                ApiKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                ApplicationName = this.GetType().ToString()
            });

            var searchListRequest = youtubeService.Search.List("snippet");
            searchListRequest.Q = "RSSB"; // Replace with your search term.
            searchListRequest.MaxResults = 5;
            searchListRequest.ChannelId = "UCaxt22KHbK-AoPJCfXU034g";


            // Call the search.list method to retrieve results matching the specified query term.
            var searchListResponse = await searchListRequest.ExecuteAsync();

            List<string> videos = new List<string>();
            List<string> channels = new List<string>();
            List<string> playlists = new List<string>();

            // Add each result to the appropriate list, and then display the lists of
            // matching videos, channels, and playlists.
            foreach (var searchResult in searchListResponse.Items)
            {
                switch (searchResult.Id.Kind)
                {
                    case "youtube#video":
                        videos.Add(String.Format("{0} ({1})", searchResult.Snippet.Title, searchResult.Id.VideoId));
                        break;

                    case "youtube#channel":
                        channels.Add(String.Format("{0} ({1})", searchResult.Snippet.Title, searchResult.Id.ChannelId));
                        break;

                    case "youtube#playlist":
                        playlists.Add(String.Format("{0} ({1})", searchResult.Snippet.Title, searchResult.Id.PlaylistId));
                        break;
                }
            }
        }
    }
}

Я смог зарегистрироваться на облачной платформе Google и получил свой ключ API, а также зарегистрировался API поиска YouTube API v3, и я вижу на странице Metrics API, что я вызвал свой метод 3 раза. Итак, Google принимает мои звонки, но я ничего не получаю. Вероятно, это что-то с моей стороны, и я надеюсь, что это будет легко заметить.

Спасибо за вашу помощь.

...