Dashang G. Makwana
Dashang G. Makwana

Reputation: 387

Twitter callback not working in ASP.MVC application

I am using the Tweetsharp library and the user to be able to post twitter status from my site .

The code for the HomeController is below, and the problem is that the calllback is not functioning properly. Twitter is not accepting localhost, so in Application setting I have kept it blank, nnd in code I am sending a callback url.

'using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TweetSharp;
using System.Web.Configuration;
using Microsoft.Web.WebPages.OAuth;

namespace youtube.Controllers
{
    public class HomeController : Controller
    {
        private string ConsumerKey = WebConfigurationManager.AppSettings["ConsumerKey"];
        private string ConsumerSecret = WebConfigurationManager.AppSettings["ConsumerSecret"];

        public ActionResult Index()
        {

            return View();
        }

        public ActionResult Authorize()
        {
            string _consumerKey = System.Configuration.ConfigurationManager.AppSettings["ConsumerKey"];
            string _consumerSecret = System.Configuration.ConfigurationManager.AppSettings["ConsumerSecret"];
            TwitterService service = new TwitterService(_consumerKey, _consumerSecret);
            //service.
            OAuthRequestToken requestToken = service.GetRequestToken();

            var uri = service.GetAuthorizationUri(requestToken,"http://localhost:50852/AuthorizeCallBack");
            return new RedirectResult(uri.ToString(), false);
        }


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


                TwitterService service = new TwitterService(ConsumerKey, ConsumerSecret);
                OAuthAccessToken accessToken = service.GetAccessToken(requestToken, oauth_verifier);


                service.AuthenticateWith(accessToken.Token, accessToken.TokenSecret);
                TwitterUser user = service.VerifyCredentials();
                ViewBag.Message = string.Format("Your username is {0}", user.ScreenName);
                return View();
        }


    }

}'

Upvotes: 1

Views: 596

Answers (1)

Burak Dobur
Burak Dobur

Reputation: 98

Twitter accepts:

http://127.0.0.1:{port}/anything

At least it's working for me.

Upvotes: 2

Related Questions