user1769787
user1769787

Reputation: 41

How to use local server for tweetsharp application

I have made a demo which is about authenticate the user through tWitter.

I want to callback to this url http://localhost:56501/home/authorize.

When I tried to set this url in my application settings it's not work. I got the error that url is not valid.

Do someone help me on get it worked on my side.

I have run some code from here https://github.com/danielcrenna/tweetsharp

Upvotes: 0

Views: 525

Answers (1)

zentix
zentix

Reputation: 11

At first you need to set callback link in the your twitter application (http://dev.twitter.com/apps/). Replase "localhost" with "127.0.0.1". For example, mine looks like - http ://127.0. 0.1:31820 /Home/AuthorizeCallback

Create TwitterService instanse using you ConsumerKey and ConsumerSecret.

var service = new TwitterService(_consumerKey, _consumerSecret);

Following method gets request token:

public ActionResult Login()
        {
            var requestToken = service.GetRequestToken(CallBackURL);

            var url = service.GetAuthenticationUrl(requestToken);

            return Redirect(url.ToString());
        }

It redirects user to twitter login form. When user enters his credentials and submits form, it redirects to your callback link.

public ActionResult AuthorizeCallback(string oauth_token, string oauth_verifier)
        {
            var requestToken = new OAuthRequestToken() {Token = oauth_token};
            var accessToken = service.GetAccessToken(requestToken, oauth_verifier);

            service.AuthenticateWith(accessToken.Token, accessToken.TokenSecret);

            var twitteruser = service.VerifyCredentials();

            return RedirectToAction("Index");
        }

Good luck!

Upvotes: 1

Related Questions