来自不同频道的Livebroadcast ID

时间:2017-05-09 19:35:32

标签: c# youtube-api youtube-livestreaming-api

我尝试从另一个频道通过c#API获取实时聊天消息。 要实现这一点,我需要liveboradcast id。 我设法通过搜索获得实时视频和ID,但似乎这个id不是livebroadcast id。

这是我的代码到目前为止。 正如我所说,它返回一个视频和ID,但具有此id的广播响应为0。 例如:

“[GER / HD] Boss Riesenaffe / Megapithecus Hard,oder auch nicht;)ARK:Survival Evolved(t3CwM9MJSNI)”

任何人都知道我可以在哪里获得livebroadcast id!?

Stream SStream = new FileStream("client_secrets.json", FileMode.Open);

        UserCredential Credentials = await GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(SStream).Secrets, new[] { YouTubeService.Scope.YoutubeForceSsl }, "user", CancellationToken.None, new FileDataStore(this.GetType().ToString()));


        Service = new YouTubeService(new BaseClientService.Initializer
        {
            HttpClientInitializer = Credentials,
            ApplicationName = "name"
        });

        var searchListRequest = Service.Search.List("snippet");

        searchListRequest.EventType = SearchResource.ListRequest.EventTypeEnum.Live;

        searchListRequest.Type = "video";

        searchListRequest.ChannelId = "thechannelid";

        searchListRequest.MaxResults = 50;

        var searchListResponse = await searchListRequest.ExecuteAsync();

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

        string ID = null;
        foreach (var searchResult in searchListResponse.Items)

        {

            switch (searchResult.Id.Kind)

            {
                case "youtube#video":
                    ID = searchResult.Id.VideoId;
                    videos.Add(String.Format("{0} ({1})", searchResult.Snippet.Title, searchResult.Id.VideoId));
                    break;
            }
        }

        Console.WriteLine(String.Format("Videos:\n{0}\n", string.Join("\n", videos)));

        LiveBroadcastsResource.ListRequest Request = Service.LiveBroadcasts.List("id,snippet,contentDetails,status");
        Request.BroadcastType = LiveBroadcastsResource.ListRequest.BroadcastTypeEnum.All;
        //Request.BroadcastStatus = LiveBroadcastsResource.ListRequest.BroadcastStatusEnum.Active;
        Request.MaxResults = 10;
        Request.Id = ID;
        Console.WriteLine("ID: " + Request.Id);

        //Request.Mine = false;

        var BroadCastResponse = Request.Execute();
        Console.WriteLine(BroadCastResponse.Items.Count);
        foreach (LiveBroadcast c in BroadCastResponse.Items)
        {
            Console.WriteLine("Title: " + c.Snippet.Title);
        }

0 个答案:

没有答案