private void GetSocialFeedSettingInfo() { SocialFeedController objController = new SocialFeedController(); SocialFeedSettingInfo objSetting = objController.GetSocialFeedSettingInfo(); if (objSetting != null) { isFacebookEnabled = objSetting.EnableFacebook; isTwitterEnabled = objSetting.EnableTwitter; isLinkedInEnabled = objSetting.EnableLinkedIn; FBAppID = objSetting.FBAppID; FBSecret = objSetting.FBAppSecret; TwitterConsumerKey = objSetting.TwitterConsumerKey; TwitterConsumerSecret = objSetting.TwitterConsumerSecret; LinkedInAppID = objSetting.LinkedInAppID; LinkedInSecret = objSetting.LinkedInAppSecret; } }
private void BindSearchContents() { List <SuggestedPostInfo> lstSuggestedPosts = new List <SuggestedPostInfo>(); SocialFeedController feedController = new SocialFeedController(); lstSuggestedPosts = feedController.GetTopSuggestions(); if (lstSuggestedPosts != null && lstSuggestedPosts.Count > 0) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < lstSuggestedPosts.Count; i++) { SuggestedPostInfo response = lstSuggestedPosts[i]; sb.Append("<div class='postMessage'>"); sb.Append("<div class='msgContent' data-resultid='" + response.ResultID + "' data-msgid='" + response.MessageID + "' data-msgpostid='" + response.MediaPostID + "'>" + response.Message + "</div>"); sb.Append("<div class='postActions'>"); sb.Append("<div class='total-shares'>" + response.Share_Count + " <span> Shares</span></div>"); sb.Append("<div class='source twitter'> <span>(" + response.Lang + ")</span> </div>"); sb.Append("<div class='total-favorites'>" + response.Favourite_Count + "<span>Favourites </span> </div>"); sb.Append("</div>"); sb.Append("<div class='reportingTags'>"); sb.Append("<div><span>User : </span>" + response.UsrName + " (" + response.UsrScreenName + ")" + " - " + response.UsrLocation + "</div>"); sb.Append("<div><span> Type : </span> " + response.ResultType + "</div>"); sb.Append("<div><span>Created On : </span>" + response.CreatedOn + "</div>"); sb.Append("<button type='button' class='btnSharePost icon-edit sfBtn smlbtn-primary' >Edit</button>"); sb.Append("</div>"); sb.Append("</div>"); //sb.Append("$('.btnSharePost').on('click', function () { SocialFeedShare.UseCurrentPost(this); });"); } ltrSearchContainer.Text = sb.ToString(); } }
private void GetSocialFeedSettingInfo() { SocialFeedController objController = new SocialFeedController(); SocialFeedSettingInfo objSetting = objController.GetSocialFeedSettingInfo(); if (objSetting != null) { hdnSettingID.Value = objSetting.SettingID.ToString(); cbFacebook.Checked = objSetting.EnableFacebook; txtFacebookAppID.Text = objSetting.FBAppID; txtFacebookAppSecret.Text = objSetting.FBAppSecret; cbTwitter.Checked = objSetting.EnableTwitter; txtTwitterConsumerKey.Text = objSetting.TwitterConsumerKey; txtTwitterConsumerSecret.Text = objSetting.TwitterConsumerSecret; cbLinkedIn.Checked = objSetting.EnableLinkedIn; txtLinkedInAppID.Text = objSetting.LinkedInAppID; txtLinkedInAppSecret.Text = objSetting.LinkedInAppSecret; txtLinkedInCompanyID.Text = objSetting.LinkedInCompanyID; } }
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 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); }
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); }
protected void btnSaveButton_Click(object sender, EventArgs e) { string errorMessage = string.Empty; bool IsFBEnabled = cbFacebook.Checked; string FBID = txtFacebookAppID.Text.Trim(); string FBSecret = txtFacebookAppSecret.Text.Trim(); bool IsTwitterEnabled = cbTwitter.Checked; string twitterConsumerKey = txtTwitterConsumerKey.Text.Trim(); string twitterConsumerSecret = txtTwitterConsumerSecret.Text.Trim(); bool IsLinkedInEnabled = cbLinkedIn.Checked; string linkedInAppID = txtLinkedInAppID.Text.Trim(); string linkedInAppSecret = txtLinkedInAppSecret.Text.Trim(); string linkedInCompanyPageID = txtLinkedInCompanyID.Text.Trim(); if (IsFBEnabled) { if (FBID == string.Empty) { errorMessage = "please enter Facebook APP ID"; } if (FBSecret == string.Empty) { errorMessage += "\nplease enter Facebook App Secret"; } } if (IsTwitterEnabled) { if (twitterConsumerKey == string.Empty) { errorMessage = "\nplease enter Twitter Consumer Key"; } if (twitterConsumerSecret == string.Empty) { errorMessage += "\nplease enter Twitter Consumer Secret"; } } if (IsLinkedInEnabled) { if (linkedInAppID == string.Empty) { errorMessage = "\nplease enter LinkedIn App ID"; } if (linkedInAppSecret == string.Empty) { errorMessage += "\nplease enter LinkedIn App Secret"; } } if (errorMessage == string.Empty) { SocialFeedSettingInfo objSetting = new SocialFeedSettingInfo(); objSetting.SettingID = int.Parse(hdnSettingID.Value); objSetting.EnableFacebook = IsFBEnabled; objSetting.FBAppID = FBID; objSetting.FBAppSecret = FBSecret; objSetting.EnableLinkedIn = IsLinkedInEnabled; objSetting.LinkedInAppID = linkedInAppID; objSetting.LinkedInAppSecret = linkedInAppSecret; objSetting.LinkedInCompanyID = linkedInCompanyPageID; objSetting.EnableTwitter = IsTwitterEnabled; objSetting.TwitterConsumerKey = twitterConsumerKey; objSetting.TwitterConsumerSecret = twitterConsumerSecret; string loggedInUserName = GetUsername; SocialFeedController objController = new SocialFeedController(); int value = objController.SaveSocialFeedSettingInfo(objSetting); if (value == 1) { txtSuccessMessage.Text = "Settings saved Successfully"; GetSocialFeedSettingInfo(); } else { txtSuccessMessage.Text = "something went wrong. please try again"; } } else { txtSuccessMessage.Text = errorMessage; } }