Automatic PIN retrieval

Aug 15, 2011 at 3:21 AM

Hello,

Is there some way to automatically retrieve the PIN without the user having to enter details? Or maybe there is another solution to my problem. Here is the issue:

Customer has 3 different accounts. App will have dropdown to select which account to send the Tweet/Retweet from. User does not wish to keep entering PINs every time. One solution is to have ConsumerKey, ConsumerSecret, AccessToken and AccessTokenSecret for all 3 accounts stored in .config and switch those in code behind, using a SingleUserAuthorizer and the relevant details. That is somewhat cumbersome though and we'd rather not sign uo for 3 different Twitter Apps, when what we really have is 1 app and 3 user accounts.

Any ideas?

Coordinator
Aug 15, 2011 at 3:46 AM

Hi,

The normal way to handle this is to have each user do Pin authorization one time.  After the user is authorized, grab the credentials and store them in the database.  On subsequent sessions, grab credentials from the DB and load the authorizer.

Joe

Aug 16, 2011 at 3:40 AM
Edited Aug 16, 2011 at 3:42 AM

Hi Joe,

Thanks, but I'm not too certain what you are referring to by Credentials. At first I assumed to save the PIN number, but it seems that is changing every time... it is not static.

I had a look at the Twitter page on authorization and foudn this: https://dev.twitter.com/docs/auth:

------------------------------------------------------------------------

Out-of-band/PIN Code Authentication

For applications that really can't handle the full OAuth process Twitter provides the out-of-band/PIN code authentication mode, also known as <abbr title="out of band">oob</abbr>.

This authentication flow is almost identical to full OAuth except instead of being directed back to your website the user is presented with a PIN code. The user is then asked to type this PIN code into your application which will then complete the token exchange.

In the full OAuth flow this manual process is performed by the callback URL and transparently to the end user.

------------------------------------------------------------------------

This means that there is another OAuth method which does not involve the user manually entering codes. How can I use this from LinqToTwitter? I have 1 registered application and several users. I want any of the users to be able to post tweets, retweets, etc without having to enter PIN codes. What is the best solution? Please provide code sample to give me a clear idea of what needs to be done.  :-)

Regards

Matt

Coordinator
Aug 16, 2011 at 6:23 AM

Matt,

You don't save the PIN.  After you use the PIN, CompleteAuthorization requests an access token.  After CompleteAuthorization finishes, you can grab the OAuthToken and AccessToken from auth.Credentials and save them.  On subsequent calls, reuse the saved OAuthToken and AccessToken by instantiating a Credentials instance and then passing that instance to TwitterContext.

Joe

Aug 16, 2011 at 12:28 PM

Thanks, Joe. Got it working now. Appreciate the help.