0
我知道这已被问过很多次,但我已经使用linqtotwitter文档和示例中的信息以及此处的其他帖子以了解更多信息。我可以让我的新应用发送推文,但只有让我通过推文授权页面,我才能点击授权按钮继续。我不能让我的帐户使用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();
}