public bool PostTwitter()
    {
        string resultID = hdnSelectedMessageID.Value;

        string requestCode = string.Empty;

        if (Session[TwitterCodeSessionKey] != null)
        {
            requestCode = Session[TwitterCodeSessionKey].ToString();
        }

        if (requestCode == null)
        {
            Session[MessageKey] = txtFeedContent.Text.Trim();
            //Session[TitleKey] = txtTitle.Text.Trim();
            Session[ShareCodeType] = "Twitter";

            OAuthTokenResponse reqToken = OAuthUtility.GetRequestToken(
                TwitterConsumerKey, TwitterConsumerSecret, Request.Url.AbsoluteUri);


            string url = string.Format("http://twitter.com/oauth/authorize?oauth_token={0}", reqToken.Token);
            Response.Redirect(url, false);
        }
        else
        {
            if (txtFeedContent.Text.Length < 140)
            {
                string requestToken = Session[TwitterCodeSessionKey].ToString();
                string pin          = Session[TwitterAuthVerifierSessionKey].ToString();

                var tokens = OAuthUtility.GetAccessToken(
                    TwitterConsumerKey,
                    TwitterConsumerSecret,
                    requestToken,
                    pin);

                OAuthTokens accesstoken = new OAuthTokens()
                {
                    AccessToken       = tokens.Token,
                    AccessTokenSecret = tokens.TokenSecret,
                    ConsumerKey       = TwitterConsumerKey,
                    ConsumerSecret    = TwitterConsumerSecret
                };

                TwitterResponse <TwitterStatus> response = TwitterStatus.Update(
                    accesstoken,
                    txtFeedContent.Text.Trim());



                if (response != null && response.Result == RequestResult.Success)
                {
                    SocialFeedController feedController = new SocialFeedController();
                    UserChoiceInfo       userChoiceInfo = feedController.ConvertToUserChoice(response, txtFeedContent.Text, resultID);
                    int output = feedController.SaveUserChoice(userChoiceInfo);

                    if (output == 1)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    if (response != null)
                    {
                        twitterCallBackContent = response.Content;
                    }
                }
            }
            else
            {
                twitterCallBackContent = "The character length for twitter posts must be not exceed more than 140 characters.";
            }
        }


        return(false);
    }
    private bool PostLinkedIn()
    {
        string requestCode = Session[LinkedInCodeSessionKey].ToString();

        if (requestCode == null)
        {
            Session[MessageKey] = txtFeedContent.Text.Trim();
            //Session[TitleKey] = txtTitle.Text.Trim();

            var config = new LinkedInApiConfiguration(LinkedInAppID, LinkedInSecret);
            var api    = new LinkedInApi(config);

            string queryString = Request.Url.Query;

            string redirectUrl = Request.Url.AbsoluteUri;
            if (queryString.Trim() != string.Empty)
            {
                redirectUrl = redirectUrl.Replace(queryString, string.Empty);
            }

            var scope = AuthorizationScope.ReadBasicProfile | AuthorizationScope.ReadEmailAddress | AuthorizationScope.WriteShare | AuthorizationScope.ReadWriteCompanyPage;
            var state = Guid.NewGuid().ToString();
            var url   = api.OAuth2.GetAuthorizationUrl(scope, state, redirectUrl);

            Response.Redirect(url.AbsoluteUri, false);
        }
        else
        {
            int linkedInCompanyID = int.Parse(LinkedInCompanyID);

            string queryString = Request.Url.Query;

            string redirectUrl = Request.Url.AbsoluteUri;
            if (queryString.Trim() != string.Empty)
            {
                redirectUrl = redirectUrl.Replace(queryString, string.Empty);
            }

            try
            {
                string message = txtFeedContent.Text.Trim();

                var config = new LinkedInApiConfiguration(LinkedInAppID, LinkedInSecret);
                // get the APIs client
                var api = new LinkedInApi(config);
                AuthorizationAccessToken userToken = api.OAuth2.GetAccessToken(requestCode, redirectUrl);

                if (userToken != null)
                {
                    string   acessToken           = userToken.AccessToken;
                    DateTime authorizationDateUTC = userToken.AuthorizationDateUtc;
                    int?     expiresIn            = userToken.ExpiresIn;

                    AccessTokenController accessTokenController = new AccessTokenController();
                    int addUpdateResult = accessTokenController.AddLinkedInAccessToken(acessToken, authorizationDateUTC, expiresIn);
                }

                UserAuthorization user = new UserAuthorization(userToken.AccessToken);

                PostShareResult postShareResult = api.Companies.Share(
                    user,
                    linkedInCompanyID, new PostShare()
                {
                    Visibility = new Visibility()
                    {
                        Code = "anyone"
                    },
                    Comment = message
                });

                string resultID = hdnSelectedMessageID.Value;
                SocialFeedController feedController = new SocialFeedController();
                UserChoiceInfo       userChoiceInfo = feedController.ConvertToUserChoice(postShareResult.Location, postShareResult.UpdateKey, postShareResult.UpdateUrl, message, resultID);

                int output = feedController.SaveUserChoice(userChoiceInfo);

                if (output == 1)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                ProcessException(ex);
            }
        }

        return(false);
    }
    public bool PostFacebook()
    {
        string requestCode = Session[FBCodeSessionKey].ToString();

        string scope = "publish_actions";

        if (requestCode == null)
        {
            Session[MessageKey] = txtFeedContent.Text.Trim();
            string queryString = Request.Url.Query;

            string redirectUrl = Request.Url.AbsoluteUri;
            if (queryString.Trim() != string.Empty)
            {
                redirectUrl = redirectUrl.Replace(queryString, string.Empty);
            }
            string url = string.Format(
                "https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}",
                FBAppID, redirectUrl, scope);
            Response.Redirect(url, false);
        }
        else
        {
            string accessToken = string.Empty;
            //Dictionary<string, string> tokens = new Dictionary<string, string>();

            string queryString = Request.Url.Query;

            string redirectUrl = Request.Url.AbsoluteUri;
            if (queryString.Trim() != string.Empty)
            {
                redirectUrl = redirectUrl.Replace(queryString, string.Empty);
            }

            string url = string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&scope={2}&code={3}&client_secret={4}",
                                       FBAppID, redirectUrl, scope, requestCode, FBSecret);

            try
            {
                WebRequest  request  = WebRequest.Create(url);
                WebResponse response = request.GetResponse();

                dynamic responseData = null;
                using (Stream responseStream = response.GetResponseStream())
                {
                    StreamReader reader         = new StreamReader(responseStream, Encoding.UTF8);
                    String       responseString = reader.ReadToEnd();

                    try
                    {
                        responseData = JObject.Parse(responseString);
                        accessToken  = responseData.access_token;
                    }
                    catch { }

                    //foreach (string token in responseString.Split('&'))
                    //{
                    //    tokens.Add(token.Substring(0, token.IndexOf("=")),
                    //        token.Substring(token.IndexOf("=") + 1, token.Length - token.IndexOf("=") - 1));
                    //}

                    //NameValueCollection query = HttpUtility.ParseQueryString(responseString);
                    //accessToken = query["access_token"];
                }

                //string access_token = tokens["access_token"];
                dynamic parameters = new ExpandoObject();
                parameters.message = txtFeedContent.Text.Trim();

                if (accessToken != string.Empty)
                {
                    var client = new FacebookClient(accessToken);
                    //client = new FacebookClient(access_token);
                    var returnID = client.Post("/me/feed", parameters);

                    if (returnID != null)
                    {
                        if (returnID["id"] != null)
                        {
                            string rtID     = returnID["id"];
                            string message  = txtFeedContent.Text.Trim();
                            string resultID = hdnSelectedMessageID.Value;
                            SocialFeedController feedController = new SocialFeedController();
                            UserChoiceInfo       userChoiceInfo = feedController.ConvertToUserChoice(rtID, message, resultID);

                            int output = feedController.SaveUserChoice(userChoiceInfo);
                            if (output == 1)
                            {
                                return(true);
                            }
                        }
                    }
                }
                else
                {
                    facebookCallBackContent = "Unable to obtain an access token for facebook";
                }
            }
            catch (Exception ex)
            {
                facebookCallBackContent = ex.Message;
                ProcessException(ex);
            }
        }

        return(false);
    }