public string GetAnalyticsProfile(string code)
        {
            Domain.Socioboard.Helper.GoogleAnalyticsProfiles _GoogleAnalyticsProfiles;
            List<Domain.Socioboard.Helper.GoogleAnalyticsProfiles> lstGoogleAnalyticsProfiles = new List<Domain.Socioboard.Helper.GoogleAnalyticsProfiles>();
            string access_token = string.Empty;
            string refresh_token = string.Empty;
            Accounts _Accounts = new Accounts();

            try
            {
                oAuthTokenGa objToken = new oAuthTokenGa();
                objToken.ConsumerKey = ConfigurationManager.AppSettings["YtconsumerKey"];
                objToken.ConsumerSecret = ConfigurationManager.AppSettings["YtconsumerSecret"];
                objToken.RedirectUri = ConfigurationManager.AppSettings["Ytredirect_uri"];

                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);
                    logger.Error("Refresh Token Not Found = > " + ex.Message);
                    return "Refresh Token Not Found";
                }

                access_token = JData["access_token"].ToString();

                string accountsdata = _Accounts.getGaAccounts(access_token);

                JObject JAccountdata = JObject.Parse(accountsdata);

                string EmailId = JAccountdata["username"].ToString();

                foreach (var item in JAccountdata["items"])
                {
                    try
                    {
                        string accountId = item["id"].ToString();
                        string accountName = item["name"].ToString();
                        string profileData = _Accounts.getGaProfiles(access_token, accountId);
                        JObject JProfileData = JObject.Parse(profileData);
                        foreach (var item_profile in JProfileData["items"])
                        {
                            try
                            {
                                _GoogleAnalyticsProfiles = new Domain.Socioboard.Helper.GoogleAnalyticsProfiles();
                                _GoogleAnalyticsProfiles.AccessToken = access_token;
                                _GoogleAnalyticsProfiles.RefreshToken = refresh_token;
                                _GoogleAnalyticsProfiles.AccountId = accountId;
                                _GoogleAnalyticsProfiles.AccountName = accountName;
                                _GoogleAnalyticsProfiles.EmailId = EmailId;
                                _GoogleAnalyticsProfiles.ProfileId = item_profile["id"].ToString();
                                _GoogleAnalyticsProfiles.ProfileName = item_profile["name"].ToString();
                                _GoogleAnalyticsProfiles.WebPropertyId = item_profile["webPropertyId"].ToString();
                                _GoogleAnalyticsProfiles.WebsiteUrl = item_profile["websiteUrl"].ToString();
                                lstGoogleAnalyticsProfiles.Add(_GoogleAnalyticsProfiles);
                            }
                            catch (Exception ex)
                            {

                            }
                        }
                    }
                    catch (Exception e)
                    {
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("GetAnalyticsProfile = >  " + ex.Message);
            }

            return new JavaScriptSerializer().Serialize(lstGoogleAnalyticsProfiles);

        }
        public string GetAnalyticsProfile(string code)
        {
            Domain.Socioboard.Helper.GoogleAnalyticsProfiles        _GoogleAnalyticsProfiles;
            List <Domain.Socioboard.Helper.GoogleAnalyticsProfiles> lstGoogleAnalyticsProfiles = new List <Domain.Socioboard.Helper.GoogleAnalyticsProfiles>();
            string   access_token  = string.Empty;
            string   refresh_token = string.Empty;
            Accounts _Accounts     = new Accounts();

            try
            {
                oAuthTokenGa objToken = new oAuthTokenGa();
                objToken.ConsumerKey    = ConfigurationManager.AppSettings["YtconsumerKey"];
                objToken.ConsumerSecret = ConfigurationManager.AppSettings["YtconsumerSecret"];
                objToken.RedirectUri    = ConfigurationManager.AppSettings["Ytredirect_uri"];

                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);
                    logger.Error("Refresh Token Not Found = > " + ex.Message);
                    return("Refresh Token Not Found");
                }

                access_token = JData["access_token"].ToString();

                string accountsdata = _Accounts.getGaAccounts(access_token);

                JObject JAccountdata = JObject.Parse(accountsdata);

                string EmailId = JAccountdata["username"].ToString();

                foreach (var item in JAccountdata["items"])
                {
                    try
                    {
                        string  accountId    = item["id"].ToString();
                        string  accountName  = item["name"].ToString();
                        string  profileData  = _Accounts.getGaProfiles(access_token, accountId);
                        JObject JProfileData = JObject.Parse(profileData);
                        foreach (var item_profile in JProfileData["items"])
                        {
                            try
                            {
                                _GoogleAnalyticsProfiles               = new Domain.Socioboard.Helper.GoogleAnalyticsProfiles();
                                _GoogleAnalyticsProfiles.AccessToken   = access_token;
                                _GoogleAnalyticsProfiles.RefreshToken  = refresh_token;
                                _GoogleAnalyticsProfiles.AccountId     = accountId;
                                _GoogleAnalyticsProfiles.AccountName   = accountName;
                                _GoogleAnalyticsProfiles.EmailId       = EmailId;
                                _GoogleAnalyticsProfiles.ProfileId     = item_profile["id"].ToString();
                                _GoogleAnalyticsProfiles.ProfileName   = item_profile["name"].ToString();
                                _GoogleAnalyticsProfiles.WebPropertyId = item_profile["webPropertyId"].ToString();
                                _GoogleAnalyticsProfiles.WebsiteUrl    = item_profile["websiteUrl"].ToString();
                                lstGoogleAnalyticsProfiles.Add(_GoogleAnalyticsProfiles);
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                    }
                    catch (Exception e)
                    {
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("GetAnalyticsProfile = >  " + ex.Message);
            }

            return(new JavaScriptSerializer().Serialize(lstGoogleAnalyticsProfiles));
        }