0

i try to get the livechat Messages vie the c# API from a different channel. To achieve this i Need the liveboradcast id. I managed to get the live Video and id via search, but it seems this id isnt the livebroadcast id.

This is my Code so far. As i said it Returns a Video and the ID, but the Broadcast Response with this id is 0. Example:

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

Anyone know where i can get the 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);
        }
macaroni
  • 1
  • 4

1 Answers1

0

AFAIK, you can only search broadcasts that the channel you are authenticated has created.

Try using search.list:

  • Returns a collection of search results that match the query parameters specified in the API request.

As stated in this related SO post, search.list returns video from a particular channel, without being authenticated as that channel/user, if you know that channel's channelId.

HTTPS Request:

HTTP GET https://www.googleapis.com/youtube/v3/search?part=snippet&channelId={channelId}&eventType=live&type=video&key={YOUR_API_KEY}
Community
  • 1
  • 1
Mr.Rebot
  • 6,703
  • 2
  • 16
  • 91