-1

I have created an asp.net web page and I am using twitterizer.framework.dll.

Below is my c# code.

    protected void btnTwitt_Click(object sender, EventArgs e)
    {

        //OAuthTokens tokens = new OAuthTokens();
        //tokens.AccessToken = "--REDACTED--";
        //tokens.AccessTokenSecret = "--REDACTED--";
        //tokens.ConsumerKey = "--REDACTED--";
        //tokens.ConsumerSecret = "--REDACTED--";

        /////

        //TwitterResponse<TwitterUser> showUserResponse = TwitterUser.Show(tokens, "twit_er_izer");

        string TwitterUserName = "My twitter username";
        string TwitterPassword = "my password";
       // string TwitterMessage = txtShout.Text;

        if (TwitterUserName != string.Empty && TwitterPassword != string.Empty)
        {
            try
            {
                //Twitter
               // TwitterAccount twitter = new TwitterAccount(TwitterUserName, TwitterPassword);
                //Twitter tw
                Twitter twitter = new Twitter(TwitterUserName, TwitterPassword);

                string TwitterMsg = txtShout.Text;
                if (txtShout.Text.Length > 120)
                {
                    TwitterMsg = TwitterMsg.Substring(0, 130) + "... For more update logon to DailyFreeCode.com";
                }
                else
                {
                    TwitterMsg = TwitterMsg + "... For more update logon to DailyFreeCode.com";
                }
                twitter.Status.Update(TwitterMsg);
                //Twitterizer.TwitterStatus.Update(tokens,TwitterMsg);


                lblTwitMsg.Text = "Your have shout successfully on http://twitter.com/" + TwitterUserName;

            }
            catch (Exception ex)
            {
                Response.Write("<b>" + ex.Message + "</b><br>" + ex.StackTrace);
            }
        }
    }

Now, I am getting error authorization failed. On this line

twitter.Status.Update(TwitterMsg);

Plz help me, thanks!

Ricky Smith
  • 2,379
  • 1
  • 13
  • 29
sambit
  • 19
  • 3

2 Answers2

2

It appears as though you're using Twitterizer version 1.x, but trying to copy code examples from Twitterizer version 2.x. Twitter twitter = new Twitter(TwitterUserName, TwitterPassword); is a dead giveaway. 2.x no longer uses that syntax.

Twitter no longer allows access to the API by supplying username and password. The tokens ARE your username and password, in a manner of speaking.

Ricky Smith
  • 2,379
  • 1
  • 13
  • 29
  • Hii ricky ,Thanks for reply..can u plz tell me what should i do to acheive this??plz give me a sample...Thanks in advance.. – sambit Nov 10 '11 at 03:48
1

If you use the twitterizer framework you shouldn't be passing the username/password. You need to fill:

OAuthTokens tokens = new OAuthTokens();
tokens.AccessToken = "XXX";
tokens.AccessTokenSecret = "XXX";
tokens.ConsumerKey = "XXX";
tokens.ConsumerSecret = "XXX";

you can do this by using the following three methods from the framework:

1:

public static Uri BuildAuthorizationUri(
    string requestToken
)

2:

public static OAuthTokenResponse GetRequestToken(
    string consumerKey,
    string consumerSecret,
    string callbackAddress
)

3:

OAuthTokenResponse accessToken = OAuthUtility.GetAccessToken(consumerKey, consumerSecret, requestToken, verifier);

look it up here

Tjassens
  • 922
  • 6
  • 9
  • hii thanks for reply..i did like this way..but still i am not able to update my status in twitter..below is my code plz help me out... using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Twitterizer; using Twitterizer.Framework; – sambit Nov 10 '11 at 03:37
  • please give your complete code. place it above and also provide us your stacktrace... – Tjassens Nov 10 '11 at 07:42