This project has moved and is read-only. For the latest updates, please go here.

Update My Status

Jul 10, 2014 at 3:51 PM
Edited Jul 10, 2014 at 3:53 PM

Perhaps a newbie question. I have an ASP.NET app that successfully posted a status update to my companies twitter account when certain events happened. This worked great until the api 1.1 was required and we got the 401 error. I did not use LinqToTwitter to do this.

Our code did not post or require the app's user to login/authenticate because it did not post to "their" status, but rather to our twitter account.

I am trying to get a simple VB.NET app working and using LinqToTwitterCP.dll ver. 2.1.12. VS 2010 and .Net 4.0.

When I execute the code below, my app opens a web browser and displays a twitter page asking for authorization for my 'TweetApp' to access my personal Twitter account (which I am logged into) on the line auth.GoToTwitterAuthorization.

When I click authorize on the Twitter page, it gives me a PIN and tells me enter that PIN into my twitter app. The code then gets a 401 error on the auth.Authorize() line.
        Dim credentials As IOAuthCredentials = New InMemoryCredentials

        credentials.ConsumerKey = "my consumer key"
        credentials.ConsumerSecret = "my secret"

        Dim auth As PinAuthorizer = New PinAuthorizer()
        auth.Credentials = credentials
        auth.GetPin = AddressOf VerifierCallback
        auth.GoToTwitterAuthorization = Function(pageLink) Process.Start(pageLink)
So, my question is. If I want to just post to MY company account and not interact with any end user accounts, is this the correct method? Even though this is not my end goal, I am also not sure how to enter the 'PIN' as directed by the twitter page.

I am obliviously very confused. ;-) I know that the cosumerkey / ConsumerSecret are derived from my 'app' defined in my Twitter account. But All I want to do is automate status updates to my account. I do not want to access or use the end users account, just mine.

Thanks in advance,

Jul 18, 2014 at 9:20 PM
Considering that Twitter requires a user context (logged in user) in order to post statuses, Pin Auth is a perfectly valid way to achieve this. As for handling Pin Auth, there are two ways of doing it in LinqToTwitter that I'm aware of. Please Note that these methods are for LinqToTwitter 3.0, so they may more may not exist in the version you're using. If they do not then hopefully something similar to them exists.

First Method is to do the whole authentication process in one call. There's a source code demo for this in his console demo file,
static IAuthorizer DoPinOAuth()
            var auth = new PinAuthorizer()
                CredentialStore = new InMemoryCredentialStore
                    ConsumerKey = ConfigurationManager.AppSettings["consumerKey"],
                    ConsumerSecret = ConfigurationManager.AppSettings["consumerSecret"]
                GoToTwitterAuthorization = pageLink => Process.Start(pageLink),
                GetPin = () =>
                        "\nAfter authorizing this application, Twitter " +
                        "will give you a 7-digit PIN Number.\n");
                    Console.Write("Enter the PIN number here: ");
                    return Console.ReadLine();

            return auth;
Just a quick explanation of some of whats going on here. The line containing GoToTwitterAuthorization opens up a browser to the page where twitter posts the Pin number that the user needs to verify. GetPin takes a task/lamda that returns a pin number. This is how you input the pin into the authorizer. Then once all of this is done you call AuthorizeAsync on the authorizer.

The other method is for if you are not capable of immediately getting the pin number. What you can do is set the authorizer up like in the code, except do not create a GetPin for it. Leave GetPin out for this method, but still include your method of opening up the Twitter Page in GoToTwitterAuthorization. Once this is complete you can call BeginAuthorizeAsync on the authorizer. This will start the process of authorizing. In order to complete it, you then call CompleteAuthorizeAsync on the authorizer with the pin number. Example:
await auth.CompleteAuthorizeAsync(PinNumber)
I hope this was able to clear things up for you despite being for version 3.0