locked
twitter api error :The remote server returned an error: (401) RRS feed

  • Question

  • User-1059320475 posted

    hi 

    i don't know english very well im sorry for that

    now i want to integrate twitter to my site. at local not problem but when i publish site at host it gives "The remote server returned an error: (401)" error. what can i do?

    imgtwit works as connect twitter and get user info. code below

     

        protected void imgTwit_Click(object sender, ImageClickEventArgs 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, Request.Url.AbsoluteUri);
    
    
    
                //Step 2: Redirect User to Requested Token
    
                Response.Redirect("http://twitter.com/oauth/authorize?oauth_token=" + RequestToken.Token);
    
    
    
            }
    
        }

     

     

     at page_load i get usertoken and post tweet. code below

        protected void Page_Load(object sender, EventArgs e)
    
        {
    
            DataRow dr;
    
            if (!IsPostBack)
    
            {
    
               //get database record to datarow
    
                //tweet
    
                if (Request.QueryString["oauth_token"] != null)
    
                {
    
                    //For Valid User
    
                    var consumerKey = ConfigurationManager.AppSettings["consumerKey"];
    
                    var consumerSecret = ConfigurationManager.AppSettings["consumerSecret"];
    
                    string Oauth_Token = Request.QueryString["oauth_token"].ToString();
    
                    string Oauth_verifier = Request.QueryString["oauth_verifier"].ToString();
    
                    var UserToken = OAuthUtility.GetAccessToken(consumerKey, consumerSecret, Oauth_Token, Oauth_verifier);
    
    
    
                    OAuthTokens accessToken = new OAuthTokens();
    
                    accessToken.AccessToken = UserToken.Token;
    
                    accessToken.AccessTokenSecret = UserToken.TokenSecret;
    
                    accessToken.ConsumerKey = consumerKey;
    
                    accessToken.ConsumerSecret = consumerSecret;
    
                    string PostMessage = "asp.net message";
    
                    TwitterResponse<TwitterStatus> tweetResponse = TwitterStatus.Update(accessToken, PostMessage);
    
                    if (tweetResponse.Result == RequestResult.Success)
    
                    {
    
                        // Tweet posted successfully!
    
                    }
    
                    else
    
                    {
    
                        // Something bad happened
    
                    }
    
                }
    
                //end tweet
    
            }
    
        }

    it's urgent please help

    Sunday, March 27, 2011 8:37 AM

All replies

  • User1546878023 posted

    Perhaps you have not copied your web.config file to the website?

    Sunday, March 27, 2011 3:47 PM
  • User-1059320475 posted

    i copy web config file to website

    Monday, March 28, 2011 3:08 AM
  • User1546878023 posted

    Try wrapping you code with a try catch and rethrow an exception displaying the username and password, just to ensure that this information is read correctly from web.config

    Wednesday, March 30, 2011 3:53 PM