protected void btnPostMsg_Click(object sender, EventArgs e) { try { FacebookClient fbClient = new FacebookClient(); txtFBResponse.Text = fbClient.postMessage("me", fbAccessToken.Text, txtFBRequest.Text); } catch (Exception ex) { txtFBResponse.Text = "Error occurred while posting facebook post! " + ex.Message; } }
/// <summary> /// Post messages to various social media sites /// </summary> /// <param name="message"></param> /// <param name="channels"></param> /// <param name="fbUserId"></param> /// <param name="fbToken"></param> /// <param name="twToken"></param> /// <param name="twTokenSecret"></param> /// <returns></returns> public List<PostResponse> postMessage(string message, string channels, string fbUserId, string fbToken, string twToken, string twTokenSecret) { List<PostResponse> response = new List<PostResponse>(); if (channels.ToLower().Contains(Channel.Facebook.ToString().ToLower())) { try { FacebookClient fbClient = new FacebookClient(); string fbPostId = fbClient.postMessage(fbUserId, fbToken, message); PostResponse pr = new PostResponse(); pr.messageId = fbPostId; pr.channel = Channel.Facebook.ToString(); response.Add(pr); } catch { throw; } } if (channels.ToLower().Contains(Channel.Twitter.ToString().ToLower())) { try { TwitterClient twClient = new TwitterClient(); string twId = twClient.postTweet(message, twToken, twTokenSecret); PostResponse pr = new PostResponse(); pr.messageId = twId; pr.channel = Channel.Twitter.ToString(); response.Add(pr); } catch { throw; } } return response; }