1
我正在關注的LinqToTwitter文檔中的文章:LinqToTwitter的OAuth未經授權
爲了讓用戶登錄到Twitter的我的C#的Web應用程序。
這裏是我的代碼
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);
}
不過我是從線得到一個HTTP 401:
auth.BeginAuthorization(Request.Url);
這裏的堆棧跟蹤:
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)
憑證有兩種ConsumerKey和ConsumerSecret用於我的Twitter應用程序集。
我該如何授權我的用戶?
謝謝!最後它證明了未設置CallbackURL的組合以及允許通過應用程序進行身份驗證被禁用的選項。 – Liath
好點 - 我更新了常見問題表明問題可能由多個問題引起。 –