예제 #1
0
        public async Task <string> GetLiveStreamIdIfLive(int userId)
        {
            var dataStore = new YoutubeDataStore();

            var credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                secrets,
                new[] { YouTubeService.Scope.YoutubeReadonly },
                userId.ToString(),
                CancellationToken.None,
                new YoutubeDataStore(),
                new AppCodeReciever()
                );

            using (var youtubeService = new YouTubeService(new BaseClientService.Initializer
            {
                HttpClientInitializer = credential,
                ApplicationName = "Brothership"
            }))

            {
                var channelsListRequest = youtubeService.LiveBroadcasts.List("id");

                channelsListRequest.BroadcastStatus = LiveBroadcastsResource.ListRequest.BroadcastStatusEnum.Active;
                channelsListRequest.BroadcastType   = LiveBroadcastsResource.ListRequest.BroadcastTypeEnum.All;

                var channelsListResponse = await channelsListRequest.ExecuteAsync();

                return((channelsListResponse.Items.Count >= 1) ? channelsListResponse.Items[0].Id : null);
            }
        }
예제 #2
0
        public async Task <string> GetChannelId(int userId)
        {
            var dataStore = new YoutubeDataStore();

            var credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                secrets,
                new[] { YouTubeService.Scope.YoutubeReadonly },
                userId.ToString(),
                CancellationToken.None,
                new YoutubeDataStore(),
                new AppCodeReciever()
                );

            using (var youtubeService = new YouTubeService(new BaseClientService.Initializer
            {
                HttpClientInitializer = credential,
                ApplicationName = "Brothership"
            }))

            {
                var channelsListRequest = youtubeService.Channels.List("contentDetails");
                channelsListRequest.Mine = true;

                var channelsListResponse = await channelsListRequest.ExecuteAsync();

                return(channelsListResponse.Items[0].Id);
            }
        }