How to post a tweet (API)


#1

Hello,

I have set up an account with below settings and simply wonder how I will create a text tweet from my website.

Thank you!

My settings in: https://apps.twitter.com/app/

Access level Read and write (modify app permissions)
Callback URL http://jackpotcity.co/dummypagefortasks.aspx
Sign in with Twitter Yes
Consumer_Key = “Manydifferentlettersandnumbershere1”;
Consumer_Secret = “Manydifferentlettersandnumbershere2”;


#2

You’d have to write an app using one of the available client libraries. Alternatively you could use Twitter for Websites widgets.


#3

Thank you for your answer!

Yes, I haved tried to use Twitterizer and seems to be so close to make it work. It seems that I have put up the code correctly (but hope something is wrong as it still doesn’t work).

To mention is that my framwork on the server is set to 2.0 and not 4.0
(I am not sure if this has any importance for the problem)

I have followed this example where I put this on my ASP.net website:
https://www.youtube.com/watch?v=TGEA1sgMMqU

When running the code I am redirected to “Confirm my application” where I do that, then I am redirected back to my website as it did in the example.

I get returned string for those lines as seen in the code which seems that some kind of connections is done:
//I get returned strings for all 4 values
Response.Write(tokens.Token.ToString() + “
”); //123456789-ExamplEstring1
Response.Write(tokens.TokenSecret.ToString() + “
”); //returnedloNGstringLikeThis1
Response.Write(requestToken + “
”); //returnedloNGstringLikeThis2
Response.Write(pin + “
”); //returnedloNGstringLikeThis3

However this line is runned in the end which means that something is going wrong. The string returned for this line says: “Unknown…”

This is my code in Page_Load:
protected void Page_Load(object sender, EventArgs e)
{

    System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");


    String Access_Token = "123456789-ExamplEstring1";
    String Access_Token_Secret = "ExamplEstring2";
    String Consumer_Key = "ExamplEstring3";
    String Consumer_Secret = "ExamplEstring4";


    if (Request["oauth_token"] == null)
    {
        Twitterizer.OAuthTokenResponse reqToken = Twitterizer.OAuthUtility.GetRequestToken(
            Consumer_Key,
            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 = Twitterizer.OAuthUtility.GetAccessToken(
            Consumer_Key,
            Consumer_Secret,
            requestToken,
            pin);

        Twitterizer.OAuthTokens accesstoken = new Twitterizer.OAuthTokens()
        {
            AccessToken = tokens.Token,
            AccessTokenSecret = tokens.TokenSecret,
            ConsumerKey = Consumer_Key,
            ConsumerSecret = Consumer_Secret
        };

        //I get returned strings for all 4 values
        Response.Write(tokens.Token.ToString() + "<br />"); //123456789-ExamplEstring1
        Response.Write(tokens.TokenSecret.ToString() + "<br />"); //returnedloNGstringLikeThis1
        Response.Write(requestToken + "<br />"); //returnedloNGstringLikeThis2
        Response.Write(pin + "<br />"); //returnedloNGstringLikeThis3



        Twitterizer.TwitterResponse<Twitterizer.TwitterStatus> response = Twitterizer.TwitterStatus.Update(accesstoken,
            "Hello World to Twitter");

        if (response.Result == Twitterizer.RequestResult.Success)
        {
            Response.Write("we did it!");
        }
        else
        {
            Response.Write(response.Result.ToString() + "...");
        }
    }
}