6

I'm developing a mobile application that needs access to Twitter. There's a ton of documentation relating to using the Twitter API with web apps, but I'm having a hard time finding the correct flow or any examples using out-of-band/PIN code mode for desktop & mobile applications.

Can anyone point me to a link or some code examples (preferebly in C#) that can show me how to use the Twitter API from a desktop or mobile application?

Thanks.

Jimmy Collins
  • 3,294
  • 5
  • 39
  • 57
  • I see lots of tutorials for Winforms/c#/twitter oAuth tutorials. – Shoban Feb 11 '11 at 21:56
  • Yes but I haven't found one that references out of band authentication - (the link to the relevant document on the Twitter website seems to be broken - http://dev.twitter.com/pages/auth#oob) - I need to use this as it's a mobile app. From Twitter's docs: "For these applications it can be difficult to handle a callback URL if not impossible". – Jimmy Collins Feb 11 '11 at 22:14

1 Answers1

11

There is some description of OOB flow in the Glossary section at the bottom of http://dev.twitter.com/pages/auth

out of band mode - Instead of providing a URL-based callback when acquiring a request token, "oob" is supplied. Once the user has given Twitter their account credentials, they are presented with a screen containing a PIN code and are asked to enter this code into the application. The application then sends this PIN as an oauth_verifier to the access token step to complete the exchange.

What that means in practice, compared to the normal web flow:

  1. In step (A) your app starts the flow by opening a browser window to the OAuth flow, but sends a request param of oauth_callback=oob rather than a callback URL
  2. Step (C) ends with Twitter displaying an authorization result page containing a PIN for the user (rather than making a callback to your app with the normal web flow)
  3. Step (D) requires the user to copy / type the PIN from the Twitter authentication page into your app (your app obviously needs some kind of "Waiting for authorization code..." screen for this :)
  4. Step (E) your app sends the PIN entered by the user back to Twitter in the oauth_verifier param to get an access token.

Try the OAuthConsumerWpf sample in DotNetOpenAuth http://www.dotnetopenauth.net/ for an example of OAuth Consumer code that you should be able to modify.

Jorgen Thelin
  • 1,066
  • 9
  • 23
  • Good explanation. In general, you don't need to open a browser window, just send/receive over HTTP(S). 2. In step (C), the application tells the user to go to https://api.twitter.com/oauth/authorize?oauth_token=. Twitter will ask the user to log in, authorize the application etc, and show the PIN. – reiniero Jun 15 '12 at 09:41