[英]LinqToTwitter OAuth Unauthorised
I'm following the article in the LinqToTwitter documentation: 我正在关注LinqToTwitter文档中的文章:
http://linqtotwitter.codeplex.com/wikipage?title=Implementing%20OAuth%20for%20ASP.NET%20Web%20Forms&referringTitle=Learning%20to%20use%20OAuth http://linqtotwitter.codeplex.com/wikipage?title=Implementing%20OAuth%20for%20ASP.NET%20Web%20Forms&referringTitle=Learning%20to%20use%20OAuth
in order to allow users to log into my C# web application with Twitter. 为了允许用户使用Twitter登录到我的C#Web应用程序。
Here's my code 这是我的代码
private WebAuthorizer auth;
private TwitterContext twitterCtx;
protected void Page_Load(object sender, EventArgs e)
{
IOAuthCredentials credentials = new SessionStateCredentials();
if (credentials.ConsumerKey == null || credentials.ConsumerSecret == null)
{
credentials.ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"];
credentials.ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"];
}
auth = new WebAuthorizer
{
Credentials = credentials,
PerformRedirect = authUrl => Response.Redirect(authUrl)
};
if (!Page.IsPostBack)
{
auth.CompleteAuthorization(Request.Url);
}
twitterCtx = new TwitterContext(auth);
}
protected void AuthorizeTwitterButton_Click(object sender, EventArgs e)
{
auth.BeginAuthorization(Request.Url);
}
However I'm getting a Http 401 from the line: 但是我从该行得到一个Http 401:
auth.BeginAuthorization(Request.Url);
Here's the stack trace: 这是堆栈跟踪:
at LinqToTwitter.OAuthTwitter.WebResponseGet(HttpWebRequest webRequest)
at LinqToTwitter.OAuthTwitter.WebRequest(HttpMethod method, String url, String authHeader, IDictionary`2 postData)
at LinqToTwitter.OAuthTwitter.OAuthWebRequest(HttpMethod method, Request request, IDictionary`2 postData, String callback)
at LinqToTwitter.OAuthTwitter.AuthorizationLinkGet(String requestToken, String authorizeUrl, String callback, Boolean forceLogin, AuthAccessType authAccessToken)
at LinqToTwitter.WebAuthorizer.BeginAuthorization(Uri callback, Boolean forceLogin)
at LinqToTwitter.WebAuthorizer.BeginAuthorization(Uri callback)
at TwitterTest.Default.AuthorizeTwitterButton_Click(Object sender, EventArgs e) in c:\Users\agriffiths.SDASOL\Documents\Visual Studio 11\Projects\TwitterTest\TwitterTest\Default.aspx.cs:line 47
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
The credentials have both the ConsumerKey and ConsumerSecret for my Twitter application set. 这些凭据同时具有我的Twitter应用程序集的ConsumerKey和ConsumerSecret。
How can I authorise my users? 如何授权用户?
There are many reasons that Twitter API returns the HTTP 401 Unauthorized. Twitter API返回HTTP 401未经授权的原因有很多。 I've put together a LINQ to Twitter FAQ that has an item on resolving 401's. 我整理了一个LINQ to Twitter FAQ ,其中有一个关于解决401的项目。
The LINQ to Twitter Downloads page has a WebFormsDemos project you can try and there's also a WebForms demo with the downloadable source code. LINQ to Twitter 下载页面上有一个WebFormsDemos项目,您可以尝试一下,还有一个带有可下载源代码的WebForms演示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.