4
votes

Currently I am working MVC4.5 with razor, I have try to integrate Twitter API in My Application but no luck. Could you please help me how to integrate Twitter API in my Application. I have create twitter API which details following

OAuth settings

Access level Read-only About the application permission model

Consumer key - [ConsumerKey]

Consumer secret - [ConsumerSecret]

Request token URL https://api.twitter.com/oauth/request_token Authorize URL https://api.twitter.com/oauth/authorize Access token URL https://api.twitter.com/oauth/access_token Callback URL http://www.opalevents.org/

1

1 Answers

9
votes

Okay, this isn't short and I can't tell you the whole process just with a few lines or even showing some code, but I'll try to give you the directions.

1. Authentication

First of all , most of Twitter API calls need to authentication (using your consumer keys). To authenticate you have to request twitter oAuth TOKENs (that's why request and authorize URL). Without these tokens, you aren't able to make requests for API calls that require authorization.

Authentication is made via oAuth (a lot of plataforms uses oAuth to authenticate, so familiarize with that): https://dev.twitter.com/docs/auth/using-oauth

You have not specified what you need to integrate, but here explain how you need to authenticate by what you need to integrate: https://dev.twitter.com/docs/auth/obtaining-access-tokens

if you want to work with user data, you need this authentication: https://dev.twitter.com/docs/auth/implementing-sign-twitter

The basic flow is:

  1. With your consumer keys you request a token to twitter
  2. You'll redirect your application to twitter, to user sign in via twitter
  3. Twitter will throw back to your CALLBACK URL the secret token to make API calls

again, this is a brief, that's all detailed at mentioned docs above

2. Making API calls

Twitter provide a lot of services through their REST API, the documentation is great, and you can find what you need to use easily:

https://dev.twitter.com/docs/api/1.1

Basically each service method have its own url and required parameters for making a call. And when you provide it, you'll receive a (JSON) response.

To help debug, they provide an amazing API explorer, that helps A LOT:

https://dev.twitter.com/console

3. Twitter Libraries

Finally we have some library for twitter written for .NET:

https://dev.twitter.com/docs/twitter-libraries

https://github.com/danielcrenna/tweetsharp

http://linqtotwitter.codeplex.com/

Twitterizer was an amazing library, but seems they have stopped support: https://github.com/Twitterizer/Twitterizer

some Twitterizer example at Twitter: https://dev.twitter.com/docs/auth/oauth/single-user-with-examples#csharp

if someone know good ones, please edit this post.

4. Most important

And if you have some question, don't be afraid to research, read , read and read here: https://dev.twitter.com/docs