//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> Send tweet. </summary> /// /// <remarks> Olivier Gagnon, 2009-11-11. </remarks> /// /// <param name="currenttweet"> The currenttweet control. </param> /// <param name="logininfo"> The login informations. </param> /// <param name="tweetbox"> The tweetbox control. </param> //////////////////////////////////////////////////////////////////////////////////////////////////// public static void SendTweet(Tweet currenttweet, LoginInfo logininfo, TextBox tweetbox) { try { IFluentTwitter tf = FluentTwitter.CreateRequest(logininfo.TcInfo); string request = tf.AuthenticateWith(logininfo.Authtoken.Token, logininfo.Authtoken.TokenSecret).Statuses().Update(tweetbox.Text).AsJson(). Request(); RefreshStatus(currenttweet, logininfo); } catch (Exception e) { MessageBox.Show(e.Message, "Error sending tweet", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> Refresh status. </summary> /// /// <remarks> Olivier Gagnon, 2009-11-10. </remarks> /// /// <param name="currenttweet"> The currenttweet. </param> /// <param name="logininfo"> The login informations. </param> /// //////////////////////////////////////////////////////////////////////////////////////////////////// public static void RefreshStatus(Tweet currenttweet, LoginInfo logininfo) { try { currenttweet.TweetText.Text = "Retrieving status......."; currenttweet.TweetText.Update(); var request = FluentTwitter.CreateRequest().Users().ShowProfileFor(logininfo.Username).AsJson().Request(); var profile = request.AsUser(); currenttweet.TweetImage.Load(profile.ProfileImageUrl); currenttweet.TweetText.Font = (new Font("Microsoft Sans Serif", 8.25F, FontStyle.Regular, GraphicsUnit.Point, Byte.Parse("0"))); currenttweet.TweetText.Text = profile.Status.Text; currenttweet.ltimeago.Text = profile.Status.CreatedDate.ToRelativeTime(); currenttweet.lluser.Text = profile.ScreenName; currenttweet.lvia.Text = "via " + Utilities.StripHtml(profile.Status.Source); } catch (Exception e) { MessageBox.Show(e.Message, "Erreur !", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> Gets an authorisation token and puts it in the configuration file. </summary> /// /// <remarks> Olivier Gagnon, 2009-11-13. </remarks> /// /// <param name="logininfo"> The login informations. </param> //////////////////////////////////////////////////////////////////////////////////////////////////// public static void GetAuthToken(LoginInfo logininfo) { Configuration oConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); IFluentTwitter tf = FluentTwitter.CreateRequest(logininfo.TcInfo); tf.Configuration.UseUrlShortening(ShortenUrlServiceProvider.TinyUrl); OAuthToken rtoken = tf.Authentication.GetRequestToken(logininfo.TcInfo.ConsumerKey, logininfo.TcInfo.ConsumerSecret).Request().AsToken(); tf.Authentication.AuthorizeDesktop(rtoken.Token); var epb = new EnterPinBox(); logininfo.Authtoken = tf.Authentication.GetAccessToken(logininfo.TcInfo.ConsumerKey, logininfo.TcInfo.ConsumerSecret, rtoken.Token, (string)epb.PIN).Request().AsToken(); oConfig.AppSettings.Settings.Remove("atoken"); oConfig.AppSettings.Settings.Add("atoken", logininfo.Authtoken.Token); oConfig.AppSettings.Settings.Remove("atokens"); oConfig.AppSettings.Settings.Add("atokens", logininfo.Authtoken.TokenSecret); oConfig.Save(); logininfo.IsLogged = true; }