How do I use oAuth to authenticate my application from .net console application?


#1

Hi,

I would like use Twitter REST API to retrieve followers for certain Twitter users. As per the documentation, I need to use the API call
"https://api.twitter.com/1.1/users/show.json?screen_name=xxxxx" and substitute the screen name each time I need to retrieve the followers.

I have registered my application and have generated the token for this application to be used for Twitter API calls.
Since my application is a console application and it does not have an access to the browser, I need to use “PIN-based OAuth” as
per your documentation.

How do I get the “PIN” number to authenticate my application? I tried a few ways but was not able to authenticate my application for the
API call “https://api.twitter.com/1.1/users/show.json?screen_name=xxxxx” from my console application.
Unfortunately, I could not find any detailed documentation discussing this type of scenario where the client does not have access to the
web browser and need to authenticate their application using OAuth.

Please advise,

Thanks


#2

Depending on your needs and whether you plan to open this up to additional users or not, you may find it easier to just use your own access token for your app which you can get from dev.twitter.com/apps – then you can skip the obtaining an access token process entirely.

Otherwise, set your application to having no registered callback URL.

When issuing the request to oauth/request_token, set your oauth_callback parameter value to “oob”

You’ll then need to generate a authorization URL, same as the typical OAuth flow, and send the user there in a web browser. Once they enter their credentials and approve the flow, they’ll be presented with the PIN code on their screen.

Your application should at that point be prompting for this PIN code to be entered in by the user. Once entered, you then complete the oauth/access_token step, just like normalOAuth, but instead of using an oauth_verifier value we sent you in a callback, you use the PIN code as the oauth_verifier instead.