// Keep client_id,client_secret and redirect_uri the client_secrets.json
UserCredential credential;
string BoundStreamId = string.Empty;
string StreamKey=string.Empty;
using (var stream = new FileStream("client_secrets.json", FileMode.Open,
FileAccess.Read))
{
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets,
new[] { YouTubeService.Scope.Youtube,YouTubeService.Scope.YoutubeReadonly},
"user",
CancellationToken.None,
new FileDataStore(this.GetType().ToString())
);
}
if (credential != null)
{
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "MyApp" // your app name
});
LiveBroadcastsResource.ListRequest lbRequest = youtubeService.LiveBroadcasts.List("id,snippet,contentDetails,status");
lbRequest.BroadcastType = LiveBroadcastsResource.ListRequest.BroadcastTypeEnum.Persistent;
lbRequest.MaxResults = 10;
lbRequest.Mine = true;
var bcResponse = await lbRequest.ExecuteAsync();
IEnumerator<LiveBroadcast> iLB = bcResponse.Items.GetEnumerator();
while (iLB.MoveNext() && string.IsNullOrEmpty(liveChatId))
{
BoundStreamId = livebroadcast.ContentDetails.BoundStreamId;
}
LiveStreamsResource.ListRequest lsRequest =
youtubeService.LiveStreams.List("id,snippet,cdn,status");
lsRequest.MaxResults = 50;
lsRequest.Id = BoundStreamId;
var srResponse = await lsRequest.ExecuteAsync();
IEnumerator<LiveStream> iLS = srResponse.Items.GetEnumerator();
if (srResponse != null)
{
foreach(LiveStream lvStream in srResponse.Items)
{
StreamKey= lvStream.Cdn.IngestionInfo.StreamName);
}
}
}