【发布时间】:2013-02-17 08:31:35
【问题描述】:
我知道这已经被问过很多次了,但是我使用了来自 linqtotwitter 文档和示例的信息以及这里的其他帖子来达到这个目的。我可以让我的新应用程序发送推文,但只有让它带我到推特授权页面,我必须点击授权按钮才能继续。
该应用程序本身已获得授权,因此我不需要每次都输入密码,这只是它需要许可的应用程序的使用。
我知道这是因为在我的代码中没有任何地方有我的访问令牌或访问令牌秘密。我已经添加了它们,但每次我得到一个未经授权的 401(无效或过期的令牌)。
我的代码如下,或许你能看出我哪里出错了?
private IOAuthCredentials credentials = new SessionStateCredentials();
private MvcAuthorizer auth;
private TwitterContext twitterCtx;
public ActionResult Index()
{
credentials.ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"];
credentials.ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"];
credentials.AccessToken = "MYaccessTOKENhere"; // Remove this line and line below and all works fine with manual authorisation every time its called //
credentials.OAuthToken = "MYaccessTOKENsecretHERE";
auth = new MvcAuthorizer
{
Credentials = credentials
};
auth.CompleteAuthorization(Request.Url);
if (!auth.IsAuthorized)
{
Uri specialUri = new Uri(Request.Url.ToString());
return auth.BeginAuthorization(specialUri);
}
twitterCtx = new TwitterContext(auth);
twitterCtx.UpdateStatus("Test Tweet Here"); // This is the line it fails on //
return View();
}
【问题讨论】:
标签: asp.net asp.net-mvc-3 twitter oauth