Example #1
0
        private void AddYouTubeChannels(string UserId, string access_token, string Ytuserid)
        {
            Domain.Socioboard.Domain.YoutubeChannel   objYoutubeChannel;
            GlobusGooglePlusLib.Youtube.Core.Channels ObjChannel = new GlobusGooglePlusLib.Youtube.Core.Channels();
            JArray objarray = new JArray();

            try
            {
                string  part         = (oAuthTokenYoutube.Parts.contentDetails.ToString() + "," + oAuthTokenYoutube.Parts.statistics.ToString());
                string  Value        = ObjChannel.Get_Channel_List(access_token, part, 50, true);
                JObject UserChannels = JObject.Parse(@Value);
                objarray = (JArray)UserChannels["items"];
            }
            catch (Exception ex)
            {
            }

            foreach (var item in objarray)
            {
                objYoutubeChannel = new Domain.Socioboard.Domain.YoutubeChannel();
                try
                {
                    objYoutubeChannel.Id               = Guid.NewGuid();
                    objYoutubeChannel.Channelid        = item["id"].ToString();
                    objYoutubeChannel.Likesid          = item["contentDetails"]["relatedPlaylists"]["likes"].ToString();
                    objYoutubeChannel.Favoritesid      = item["contentDetails"]["relatedPlaylists"]["favorites"].ToString();
                    objYoutubeChannel.Uploadsid        = item["contentDetails"]["relatedPlaylists"]["uploads"].ToString();
                    objYoutubeChannel.Watchhistoryid   = item["contentDetails"]["relatedPlaylists"]["watchHistory"].ToString();
                    objYoutubeChannel.Watchlaterid     = item["contentDetails"]["relatedPlaylists"]["watchLater"].ToString();
                    objYoutubeChannel.Googleplususerid = Ytuserid;
                    objYoutubeChannel.UserId           = Guid.Parse(UserId);
                    try
                    {
                        string viewcnt = item["statistics"]["viewCount"].ToString();
                        objYoutubeChannel.ViewCount = Convert.ToInt32(viewcnt);
                        string videocnt = item["statistics"]["videoCount"].ToString();
                        objYoutubeChannel.VideoCount = Convert.ToInt32(videocnt);
                        string commentcnt = item["statistics"]["commentCount"].ToString();
                        objYoutubeChannel.CommentCount = Convert.ToInt32(commentcnt);
                        string Subscribercnt = item["statistics"]["subscriberCount"].ToString();
                        objYoutubeChannel.SubscriberCount = Convert.ToInt32(Subscribercnt);
                        try
                        {
                            string str = item["statistics"]["hiddenSubscriberCount"].ToString();
                            if (str == "false")
                            {
                                objYoutubeChannel.HiddenSubscriberCount = 0;
                            }
                            else
                            {
                                objYoutubeChannel.HiddenSubscriberCount = 1;
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.StackTrace);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.StackTrace);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }
                if (!objYoutubeChannelRepository.checkYoutubeChannelExists(objYoutubeChannel.Channelid, Guid.Parse(UserId)))
                {
                    YoutubeChannelRepository.Add(objYoutubeChannel);
                }
                else
                {
                    objYoutubeChannelRepository.UpdateYouTubechannel(objYoutubeChannel);
                }
            }
        }