Tweets Posting Through ASP.NET

 Register Create Twiier Account in API



DownLoad Twitter DLL Heare





   Place Consumer Key,Secret Key in WEB.ConFig



 <appSettings>

    <add key="consumerKey" value="Place Consumer Key Heare"/>
    <add key="consumerSecret" value="Place Consumer Secret Key Heare"/>
  </appSettings>


Authntication Button Click Event(Optional)


protected void btnAuthenticate_Click(object sender, EventArgs e)
        {


            // add these to web.config or your preferred location
            var consumerKey = ConfigurationManager.AppSettings["consumerKey"];
            var consumerSecret = ConfigurationManager.AppSettings["consumerSecret"];

            //If User is not valid user
            if (Request.QueryString["oauth_token"] == null)
            {
                //Step 1: Get Request Token

                OAuthTokenResponse RequestToken = OAuthUtility.GetRequestToken(consumerKey, consumerSecret, "Redirect URL Place Heare");

                //Step 2: Redirect User to Requested Token
                Response.Redirect("http://twitter.com/oauth/authorize?oauth_token=" + RequestToken.Token);
            }
            else
            {
                //For Valid User
                string Oauth_Token = Request.QueryString["oauth_token"].ToString();
                var accessToken = OAuthUtility.GetAccessToken(consumerKey, consumerSecret, Oauth_Token, "");

                lblMessage.Text = "<b>Hello "

        + accessToken.ScreenName

        + ", Welcome to Go4Sharepoint.com Twitter App<b>";

                lblMessage.Text += "<br/> Token: " + accessToken.Token;
                lblMessage.Text += "<br/> TokenSecret: " + accessToken.TokenSecret;
                lblMessage.Text += "<br/> UserId: " + accessToken.UserId;
            }
        }


Tweets Posting:


 protected void btnPost_Click(object sender, EventArgs e)
        {
            // add these to web.config or your preferred location
            var consumerKey = ConfigurationManager.AppSettings["consumerKey"];
            var consumerSecret = ConfigurationManager.AppSettings["consumerSecret"];

            OAuthTokens accessToken = new OAuthTokens();
            accessToken.AccessToken = "Place Access Token Heare ";
            accessToken.AccessTokenSecret = "Place Access Token Secret Key";
            accessToken.ConsumerKey = consumerKey;
            accessToken.ConsumerSecret = consumerSecret;


                       TwitterStatus.Update(accessToken, txtpost.Text);
        
           
         
        }

0 comments:

Post a Comment