c# asp.net 未提供必需的oauth_verifier参数

本文关键字:oauth verifier 参数 net asp | 更新日期: 2023-09-27 18:32:19

我现在在 OAuTHUSING LINQ 到 Twitter 库中面临此错误:

<?xml version="1.0" encoding="UTF-8"?> 
<hash> 
<error>Required oauth_verifier parameter not provided</error> 
<request>/oauth/access_token</request> 
</hash> 

我关注了此文档链接:https://linqtotwitter.codeplex.com/wikipage?title=Implementing%20OAuth%20for%20ASP.NET%20Web%20Forms&referringTitle=Learning%20to%20use%20OAuth要实现 OAuth 过程,我在以下行收到此错误:等待身份验证。CompleteAuthorizeAsync(new Uri(twitterCallbackUrl));

以下是完整的代码,请帮助我:

AspNetAuthorizer auth;
    string twitterCallbackUrl = "http://127.0.0.1:58192/Default.aspx";
    protected async void Page_Load(object sender, EventArgs e)
    {
        auth = new AspNetAuthorizer
        {
            CredentialStore = new SessionStateCredentialStore
            {
                ConsumerKey = ConfigurationManager.AppSettings["consumerKey"],
                ConsumerSecret = ConfigurationManager.AppSettings["consumerSecret"]
            },
            GoToTwitterAuthorization =
                twitterUrl => Response.Redirect(twitterUrl, false)
        };
        if (!Page.IsPostBack && Request.QueryString["oauth_token"] != null)
        {
            __await auth.CompleteAuthorizeAsync(new Uri(twitterCallbackUrl));__
            // This is how you access credentials after authorization.
            // The oauthToken and oauthTokenSecret do not expire.
            // You can use the userID to associate the credentials with the user.
            // You can save credentials any way you want - database, isolated 
            //   storage, etc. - it's up to you.
            // You can retrieve and load all 4 credentials on subsequent queries 
            //   to avoid the need to re-authorize.
            // When you've loaded all 4 credentials, LINQ to Twitter will let you 
            //   make queries without re-authorizing.
            //
            var credentials = auth.CredentialStore;
            string oauthToken = credentials.OAuthToken;
            string oauthTokenSecret = credentials.OAuthTokenSecret;
            string screenName = credentials.ScreenName;
            ulong userID = credentials.UserID;
            //Response.Redirect("~/Default.aspx", false);
        }
    }
    protected async void AuthorizeButton_Click(object sender, EventArgs e)
    {
        await auth.BeginAuthorizeAsync(new Uri(twitterCallbackUrl));
        //await auth.BeginAuthorizeAsync(Request.Url);
    }

c# asp.net 未提供必需的oauth_verifier参数

出现此问题的原因是,你的自定义 URL 不包含应用程序请求授权后 Twitter 返回的参数。如果在 CompleteAuthorizationAsync 上设置断点并在"即时"窗口中键入 Request.Url,您将看到以下参数:

如果您仍想手动指定 URL,则需要包含这些参数。这是一种方法:

    string completeOAuthUrl = twitterCallbackUrl + Request.Url.Query;
    await auth.CompleteAuthorizeAsync(completeOAuthUrl);

或者,您可以只使用页面 URL,因为它已经包含正确的参数:

    await auth.CompleteAuthorizeAsync(Request.Url);