Integrate Twitter in Asp.net

262 Views Asked by At
protected void Page_Load(object sender, EventArgs e)
        {
            var oauth_consumer_key = "pUw6DN1vh2PRhqIQd0w";
            var oauth_consumer_secret = "uCrFLs6x3LlKd6G9YZ2XSzvjiQZmfAM1z3TTEus";

            if(Request["oauth_token"] == null)
            {
                OAuthTokenResponse reqToken = OAuthUtility.GetRequestToken(
                    oauth_consumer_key,
                    oauth_consumer_secret,
                    Request.Url.AbsoluteUri);

                Response.Redirect(string.Format("http://twitter.com/oauth/authorize?oauth_token={0}",
                    reqToken.Token));
            }
            else
            {
                string requestToken = Request["oauth_token"].ToString();
                string pin = Request["oauth_verifier"].ToString();
                var tokens = OAuthUtility.GetAccessToken(
                    oauth_consumer_key,
                    oauth_consumer_secret,
                    requestToken,
                    pin);
                OAuthTokens accesstoken = new OAuthTokens()
                {
                    AccessToken = tokens.Token,
                    AccessTokenSecret = tokens.TokenSecret,
                    ConsumerKey = oauth_consumer_key,
                    ConsumerSecret = oauth_consumer_secret
                };

                TwitterResponse<TwitterStatus> response = TwitterStatus.Update(
                    accesstoken,
                    "Testing!! It works (hopefully).");

                if(response.Result == RequestResult.Success)
                {
                    Response.Write("we did it!");
                }
                else
                {
                    Response.Write("it's all bad.");
                }

            }           
        }

I have integrate twitter in asp.net. but always giving me response.Result 'UNKNOWN' Message "it's all bad." i dont know what happen from my end. Install-Package twitterizer - Version 2.4.2 Refer this link Twitter Integration Link

2

There are 2 best solutions below

0
Palak Bhansali On

This is because of access is Unauthorized. please check TwitterStatus of your response object.

Alternatively, can you please check this Updated Twitterizer Integration Code.

0
Dave On

If you are running application in localhost then you have to specify localhost url and port in twitter app url like 127.0.0.1:3000. My problem was solved using this.