It is not www.twitter.com

A quick way to programmatically post to twitter is to create a URL that posts directly to their web site. This little tidbit you can find on several other blog posts out there: (link this one). Here is the C# code I am using to launch the default browser from a Winform application:

private void twitterToolStripButton_Click(object sender, EventArgs e)
{
    Cursor.Current = Cursors.WaitCursor;

    Uri twitterUri = new Uri(String.Format(
        "http://twitter.com/home/?status={0}",
        HttpUtility.UrlEncode(((INotification)_current).Tweet)));

    try
    {
        System.Diagnostics.Process.Start(twitterUri.ToString());
    }
    finally
    {
        Cursor.Current = Cursors.Default;
    }
}

This works nicely even when the Tweet has hash marks (#) etc… -- because of the HttpUtility.UrlEncode. However, in the original code I was going to www.twitter.com instead of twitter.com which is a problem – since the subnet of www redirects to the twitter.com and gives the original encoding another layer of encoding. I am not sure if this is an issue with twitter (which might be fixed) or the browser (which will probably never be fixed). Going to http://www.twitter.com creates garbage in the text area of the post like this:

 

ss1

 

Notice that in the picture the address bar has already redirected and added the extra encoding.

 

ss2

 

The moral of the story, make sure you are going to twitter.com, and not www.twitter.com when posting with this technique.

 

{6230289B-5BEE-409e-932A-2F01FA407A92}

Comments

  1. Uri.ToString can unescape characters that are necessary to interpret the URI correctly on the destination server; use Uri.AbsoluteUri instead to make sure the URI doesn't get corrupted.

    See http://blog.nerdbank.net/2008/04/uriabsoluteuri-and-uritostring-are-not.html for more information.

    ReplyDelete

Post a Comment

Popular posts from this blog

Simple WP7 Mango App for Background Tasks, Toast, and Tiles: Code Explanation

Yet once more into the breech (of altered programming logic)

How to convert SVG data to a Png Image file Using InkScape