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

Seperation of GetPin and GoToTwitterAuthorization

May 21, 2011 at 9:54 AM


          I am sort of new to Linq and I am trying to build a desktop App using WPF and Linq to twitter. I am difficulty with the following issue.

The code below is from the Linqtotwitter demo project. It is a console application which uses console.readline() to make the process wait for the pin. However I want to make an Desktop Application in WPF, I wanted to know how to rewrite the below code to make the app go to the authorization page without immediately taking the text of a  textbox  for GetPin . Is there some way I can seperate the GetPin and GoToTwitterAuthorization parts of the code so than I can get the PIN first and then authorise the Application. Replacing the "return Console.Readline()" with "return getpin.txt" doesnt work . Help willl be really appreciated.

Thank you


// validate that credentials are present
if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["twitterConsumerKey"]) ||
Console.WriteLine("You need to set twitterConsumerKey and twitterConsumerSecret in App.config/appSettings. Visit for more info.\n");
Console.Write("Press any key to exit...");

// configure the OAuth object
var auth = new PinAuthorizer
Credentials = new InMemoryCredentials
ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"],
ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"],
UseCompression = true,
GoToTwitterAuthorization = pageLink => Process.Start(pageLink),
GetPin = () =>
// this executes after user authorizes, which begins with the call to auth.Authorize() below.
Console.WriteLine("\nAfter you authorize this application, Twitter will give you a 7-digit PIN Number.\n");
Console.Write("Enter the PIN number here: ");
return Console.ReadLine();


// start the authorization process (launches Twitter authorization page).


May 21, 2011 at 9:06 PM


A couple approaches might be:

1. Check out the Silverlight demo in the downloadable source code. I know you're doing WPF, but this might give you some ideas.  The StatusUpdate.xaml and StatusUpdate.xaml.cs file show how to embed a Web browser and a text box on the page and use async calls while keeping the user on the same page.

2. Another option might be to replace the lambda code in the GetPin callback with a dialog box that pops up and asks the user to provide the PIN.  After the user clicks the OK button on the dialog, grab the pin from the Text box (perhaps validate too) and return the pin from the lambda.

Hopefully, this will give you a couple ideas.  If anyone else has their own experiences to share, that would be great.


May 23, 2011 at 11:18 AM

Thank you very much. I will give it a try.

Jun 20, 2011 at 7:23 PM

Thanks for the idea. I too was struggling on how to problem of how to populate GetPin.