C# 当使用谷歌api v3搜索youtube上传时,它将显示超过50个结果,我如何做到这一点?

C# 当使用谷歌api v3搜索youtube上传时,它将显示超过50个结果,我如何做到这一点?,c#,.net,winforms,C#,.net,Winforms,如果我将最大结果设置为400,则会出现异常,因为它应该在0-50到400之间。 所以现在为了测试,我做了50次 我怎样才能知道当它找到50个结果并将它们添加到列表中时,它会对接下来的50个结果进行另一次搜索,依此类推,直到最后 using System.Collections.Generic; using System.Linq; using System.Text; using System; using System.IO; using System.Reflection; using Sy

如果我将最大结果设置为400,则会出现异常,因为它应该在0-50到400之间。 所以现在为了测试,我做了50次

我怎样才能知道当它找到50个结果并将它们添加到列表中时,它会对接下来的50个结果进行另一次搜索,依此类推,直到最后

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;
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;


namespace Automatic_Record
{


    class Youtube_Retrieve_Uploads
    {
        public Youtube_Retrieve_Uploads()
        {
            test();
            /*try
            {
                Run().Wait();
            }
            catch (AggregateException ex)
            {
                foreach (var e in ex.InnerExceptions)
                {
                    Console.WriteLine("Error: " + e.Message);
                }
            }*/
        }

        private void test()
        {
            YouTubeService yt = new YouTubeService(new BaseClientService.Initializer() { ApiKey = "AIzaSyDcqx8nMWQL9wshpAs0Q-h0twpGd6R1BJM" });
            List<string> videos = new List<string>();

            var searchListRequest = yt.Search.List("snippet");
            searchListRequest.ChannelId = "UCUE_2qgW-nJOjOlO28uZHtQ";//"UCbe-iLd-TEl3_YQaNSm8dng";
            searchListRequest.MaxResults = 50;
            var searchListResult = searchListRequest.Execute();

            foreach (var item in searchListResult.Items)
            {
                if (item.Snippet.Title.StartsWith("Gta"))
                {
                    videos.Add("ID: " + item.Id.VideoId);
                    videos.Add("SNIPPET: " + item.Snippet.Title);
                }
            }  
        }
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用制度;
使用System.IO;
运用系统反思;
使用系统线程;
使用System.Threading.Tasks;
使用Google.api.Auth.OAuth2;
使用Google.api.Services;
使用Google.api.Upload;
使用Google.api.Util.Store;
使用Google.api.YouTube.v3;
使用Google.api.YouTube.v3.Data;
名称空间自动记录
{
类Youtube_检索_上载
{
公共Youtube_检索_上传()
{
test();
/*试一试
{
Run().Wait();
}
捕获(聚合异常)
{
foreach(ex.InnerExceptions中的变量e)
{
Console.WriteLine(“错误:+e.Message”);
}
}*/
}
专用无效测试()
{
YouTube服务yt=新的YouTube服务(新的BaseClientService.Initializer(){ApiKey=“AIzaSyDcqx8nMWQL9wshpAs0Q-h0twpGd6R1BJM”});
列表视频=新建列表();
var searchListRequest=yt.Search.List(“代码段”);
searchListRequest.ChannelId=“UCUE_2qgW-njojojolo28uzhtq”/“UCbe-iLd-TEl3_YQaNSm8dng”;
searchListRequest.MaxResults=50;
var searchListResult=searchListRequest.Execute();
foreach(searchListResult.Items中的变量项)
{
if(item.Snippet.Title.StartsWith(“Gta”))
{
添加(“ID:+item.ID.VideoId”);
添加(“片段:+item.SNIPPET.Title”);
}
}  
}

这很好,但我只得到了50个结果。我想从Gta开始获得整个视频,但一般来说,我想先得到前50个结果,然后是下50个结果,然后是下50个结果,直到没有更多的结果。

你需要使用令牌在页面中循环,以确定你在哪个页面上

通过以下示例遵循NEXTPGETOKEN变量:

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

          // Retrieve the list of videos uploaded to the authenticated user's channel.
          var playlistItemsListResponse = await playlistItemsListRequest.ExecuteAsync();

          foreach (var playlistItem in playlistItemsListResponse.Items)
          {
            // Print information about each video.
            Console.WriteLine("{0} ({1})", playlistItem.Snippet.Title, playlistItem.Snippet.ResourceId.VideoId);
          }

          nextPageToken = playlistItemsListResponse.NextPageToken;
        }
有关更多帮助和示例,请参见此链接:

Don这就是我试图做的,但是我对这个样本有一个问题。你能试着看看我关于这个样本的其他问题吗?