Beispiel #1
0
 /// <summary>
 /// Post tweet event
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void btntwPost_Click(object sender, EventArgs e)
 {
     try
     {
         TwitterClient tClient = new TwitterClient();
         txtTWResponse.Text = tClient.postTweet(txtTWRequest.Text, twToken.Text, twTknSecret.Text);
     }
     catch (Exception ex)
     {
         txtTWResponse.Text = "Error occurred while posting twitter post! " + ex.Message;
     }
 }
Beispiel #2
0
        /// <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;
        }