1

我正在使用 Tweetsharp 库和用户能够从我的网站发布 twitter 状态。

HomeController 的代码如下,问题是回调不能正常工作。Twitter 不接受 localhost,因此在应用程序设置中我将其保留为空白,在代码中我正在发送回调 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();
        }


    }

}'
4

1 回答 1

2

推特接受:

http://127.0.0.1:{port}/anything

至少它对我有用。

于 2012-11-22T15:39:32.227 回答