public static List <Domain.Socioboard.ViewModels.YoutubeProfiles> GetYoutubeAccount(string code, Helper.AppSettings _appSettings, Model.DatabaseRepository dbr) { Domain.Socioboard.ViewModels.YoutubeProfiles _YoutubeChannels; List <Domain.Socioboard.ViewModels.YoutubeProfiles> lstYoutubeProfiles = new List <Domain.Socioboard.ViewModels.YoutubeProfiles>(); string access_token = string.Empty; string refresh_token = string.Empty; Channels _Channels = new Channels(_appSettings.GoogleConsumerKey, _appSettings.GoogleConsumerSecret, _appSettings.GoogleRedirectUri); try { oAuthTokenYoutube objToken = new oAuthTokenYoutube(_appSettings.GoogleConsumerKey, _appSettings.GoogleConsumerSecret, _appSettings.GoogleRedirectUri); string accessToken = objToken.GetRefreshToken(code); JObject JData = JObject.Parse(accessToken); try { refresh_token = JData["refresh_token"].ToString(); } catch (Exception ex) { access_token = JData["access_token"].ToString(); objToken.RevokeToken(access_token); return(null); } access_token = JData["access_token"].ToString(); string channelsdata = _Channels.Get_Channel_List(access_token, "snippet,contentDetails,statistics", 50, true); JObject JChanneldata = JObject.Parse(channelsdata); foreach (var item in JChanneldata["items"]) { try { string channelid = item["id"].ToString(); string channelname = item["snippet"]["title"].ToString(); string channelimage = item["snippet"]["thumbnails"]["default"]["url"].ToString(); channelimage = channelimage.Replace(".jpg", ""); string publishdate = item["snippet"]["publishedAt"].ToString(); string viewscount = item["statistics"]["viewCount"].ToString(); string commentscount = item["statistics"]["commentCount"].ToString(); string subscriberscount = item["statistics"]["subscriberCount"].ToString(); string videoscount = item["statistics"]["videoCount"].ToString(); string channeldescrip = item["snippet"]["description"].ToString(); #region Update Access and refresh token after authentication for every time //try //{ // List<Domain.Socioboard.Models.YoutubeChannel> lstYTChannel = dbr.Find<Domain.Socioboard.Models.YoutubeChannel>(t => t.YtubeChannelId.Equals(channelid)).ToList(); // if (lstYTChannel != null && lstYTChannel.Count() > 0) // { // lstYTChannel.First().AccessToken = access_token; // lstYTChannel.First().RefreshToken = refresh_token; // dbr.Update<Domain.Socioboard.Models.YoutubeChannel>(lstYTChannel.First()); // } //} //catch(Exception ex) //{ //} #endregion try { _YoutubeChannels = new Domain.Socioboard.ViewModels.YoutubeProfiles(); _YoutubeChannels.Accesstoken = access_token; _YoutubeChannels.Refreshtoken = refresh_token; _YoutubeChannels.YtChannelId = channelid; _YoutubeChannels.YtChannelName = channelname; _YoutubeChannels.YtChannelImage = channelimage; _YoutubeChannels.PublishDate = publishdate; _YoutubeChannels.viewscount = viewscount; _YoutubeChannels.commentscount = commentscount; _YoutubeChannels.subscriberscount = subscriberscount; _YoutubeChannels.videoscount = videoscount; _YoutubeChannels.YtChannelDescrip = channeldescrip; lstYoutubeProfiles.Add(_YoutubeChannels); } catch (Exception ex) { } } catch (Exception e) { } } } catch { } return(lstYoutubeProfiles); }
public static List <Domain.Socioboard.ViewModels.YoutubeProfiles> GetYoutubeAccount(string code, Helper.AppSettings _appSettings) { Domain.Socioboard.ViewModels.YoutubeProfiles _YoutubeChannels; List <Domain.Socioboard.ViewModels.YoutubeProfiles> lstYoutubeProfiles = new List <Domain.Socioboard.ViewModels.YoutubeProfiles>(); string access_token = string.Empty; string refresh_token = string.Empty; Channels _Channels = new Channels("575089347457-74q0u81gj88ve5bfdmbklcf2dnc0353q.apps.googleusercontent.com", "JRtS_TaeYpKOJWBCqt9h8-iG", "http://localhost:9821/GoogleManager/Google"); try { oAuthTokenYoutube objToken = new oAuthTokenYoutube("575089347457-74q0u81gj88ve5bfdmbklcf2dnc0353q.apps.googleusercontent.com", "JRtS_TaeYpKOJWBCqt9h8-iG", "http://localhost:9821/GoogleManager/Google"); string accessToken = objToken.GetRefreshToken(code); JObject JData = JObject.Parse(accessToken); try { refresh_token = JData["refresh_token"].ToString(); } catch (Exception ex) { access_token = JData["access_token"].ToString(); objToken.RevokeToken(access_token); return(null); } access_token = JData["access_token"].ToString(); string channelsdata = _Channels.Get_Channel_List(access_token, "snippet,contentDetails,statistics", 50, true); JObject JChanneldata = JObject.Parse(channelsdata); foreach (var item in JChanneldata["items"]) { try { string channelid = item["id"].ToString(); string channelname = item["snippet"]["title"].ToString(); string channelimage = item["snippet"]["thumbnails"]["default"]["url"].ToString(); string publishdate = item["snippet"]["publishedAt"].ToString(); string viewscount = item["statistics"]["viewCount"].ToString(); string commentscount = item["statistics"]["commentCount"].ToString(); string subscriberscount = item["statistics"]["subscriberCount"].ToString(); string videoscount = item["statistics"]["videoCount"].ToString(); string channeldescrip = item["snippet"]["description"].ToString(); try { _YoutubeChannels = new Domain.Socioboard.ViewModels.YoutubeProfiles(); _YoutubeChannels.Accesstoken = access_token; _YoutubeChannels.Refreshtoken = refresh_token; _YoutubeChannels.YtChannelId = channelid; _YoutubeChannels.YtChannelName = channelname; _YoutubeChannels.YtChannelImage = channelimage; _YoutubeChannels.PublishDate = publishdate; _YoutubeChannels.viewscount = viewscount; _YoutubeChannels.commentscount = commentscount; _YoutubeChannels.subscriberscount = subscriberscount; _YoutubeChannels.videoscount = videoscount; _YoutubeChannels.YtChannelDescrip = channeldescrip; lstYoutubeProfiles.Add(_YoutubeChannels); } catch (Exception ex) { } } catch (Exception e) { } } } catch { } return(lstYoutubeProfiles); }