Search code examples
c#twitterexceptionhttp-status-code-401linq-to-twitter

How to update status on twitter using C# and LINQ to Twitter library


I am writing an Metrol Style App to update status on my Twitter. I use LINQ to Twitter library. But I don't understand why my app throws exception 401 Unauthorized. Here is my code:

private void UpdateStatus()
{
     // configure the OAuth object
    var auth = new SingleUserAuthorizer
    {
        Credentials = new InMemoryCredentials
        {
            ConsumerKey = "ConsumerKey",
            ConsumerSecret = "ConsumerSecret",
            OAuthToken = "TwitterAccessToken",
            AccessToken = "TwitterAccessTokenSecret"
        }
    };

    using (var twitterCtx = new TwitterContext(auth, "https://api.twitter.com/1/", "https://search.twitter.com/"))
    {
        var tweet = twitterCtx.UpdateStatus("Hi everybody!"); // error here

        viewTextBlock.Text = String.Empty;
        viewTextBlock.Text = viewTextBlock.Text + "Status returned: " +
                                            "(" + tweet.StatusID + ")" +
                                            tweet.User.Name + ", " +
                                            tweet.Text + "\n";
    }
}

Solution

  • I just posted a blog entry on using OAuth in Windows 8 with LINQ to Twitter:

    http://geekswithblogs.net/WinAZ/archive/2012/07/02/using-linq-to-twitter-oauth-with-windows-8.aspx

    I also included a 401 FAQ in the LINQ to Twitter docs here:

    http://linqtotwitter.codeplex.com/wikipage?title=LINQ%20to%20Twitter%20FAQ&referringTitle=Documentation