1
我正在使用Tweetsharp庫和用戶能夠從我的網站發佈twitter狀態。Twitter回調無法在ASP.MVC應用程序中工作
HomeController的代碼如下,問題是calllback無法正常工作。 Twitter不接受本地主機,所以在應用程序設置中,我一直保持空白,在代碼中我發送一個回調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();
}
}
}'
你得到了什麼錯誤? –