Skip to content

Commit

Permalink
Fix YouTubeChatProvider Error (#248)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
degenone and github-actions[bot] authored Oct 19, 2023
1 parent d483cd4 commit 14203cb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/TagzApp.Providers.YouTubeChat/YouTubeChatProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ public async Task<string> GetChannelForUserAsync()
channelRequest.Mine = true;
var channels = channelRequest.Execute();

return channels.Items.First().Snippet.Title;
// Not sure if this is needed, can't replicate "fisrt" error. (https://github.com/FritzAndFriends/TagzApp/issues/241)
return channels.Items?.First().Snippet.Title ?? "Unknown Channel Title";

}

Expand All @@ -156,7 +157,17 @@ public async Task<IEnumerable<YouTubeBroadcast>> GetBroadcastsForUser()
var listRequest = service.LiveBroadcasts.List("snippet");
listRequest.Mine = true;
listRequest.BroadcastType = LiveBroadcastsResource.ListRequest.BroadcastTypeEnum.Event__;
var broadcasts = listRequest.Execute();
LiveBroadcastListResponse broadcasts;
try
{
broadcasts = listRequest.Execute();
}
catch (Google.GoogleApiException ex)
{
// GoogleApiException: The service youtube has thrown an exception. HttpStatusCode is Forbidden. The user is not enabled for live streaming.
Console.WriteLine($"Exception while fetching YouTube broadcasts: {ex.Message}");
return Enumerable.Empty<YouTubeBroadcast>();
}

var outBroadcasts = new List<YouTubeBroadcast>();
outBroadcasts.AddRange(broadcasts.Items
Expand Down
4 changes: 4 additions & 0 deletions src/TagzApp.Web/Areas/Admin/Pages/YouTubeChat.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
{
<p><a href="~/Identity/Account/Manage/ExternalLogins">Login with a Google Id</a> to start connecting TagzApp to YouTube</p>
}
else if (Model.Broadcasts.Count() == 0)
{
<p>There are no live events for channel: '@Model.ChannelTitle'. <strong>Consider checking the correct account is registered.</strong></p>
}
else
{

Expand Down

0 comments on commit 14203cb

Please sign in to comment.