1

i am facing this error, right now in oauthusing linq to twitter library:

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

i have followed this documentation link: https://linqtotwitter.codeplex.com/wikipage?title=Implementing%20OAuth%20for%20ASP.NET%20Web%20Forms&referringTitle=Learning%20to%20use%20OAuth to implement the OAuth process, I get the this error at following line: await auth.CompleteAuthorizeAsync(new Uri(twitterCallbackUrl));

below is the full code, please help me on this:

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);
    }
Sanjay Bathre
  • 451
  • 1
  • 5
  • 17

1 Answers1

2

The problem occurs because your custom URL doesn't include the parameters that Twitter returned after the application requested authorization. If you set a breakpoint on CompleteAuthorizationAsync and type Request.Url into the Immediate window, you'll see these parameters:

If you still want to manually specify your URL, you need to include these parameters. Here's one way to do that:

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

Alternatively, you can just use the page URL because that will already contains the proper parameters:

    await auth.CompleteAuthorizeAsync(Request.Url);
Joe Mayo
  • 7,501
  • 7
  • 41
  • 60
  • your are totally right @Joe there are two parameters: oauth_token=xxxxxxx and oauth_verifier=xyxyxyxy, Thanx a lot for helping me :) – Sanjay Bathre Nov 28 '14 at 17:50
  • instead of SessionStateCredentialStore, i want to store the credentilas in Inproc session mode, when i try InMemoryCredentialStore it starts throwing error. is there any documentation for this, if yes then please refer it to me? – Sanjay Bathre Dec 15 '14 at 12:39
  • 1
    @SanjayBathre SessionStateCredentialStore depends on ASP.NET Session State, which naturally recycles occasionally. If you're using InProc, you loose your credentials. It's best to reconfigure to use State Server or SQL Server. Here's an article to describe how ASP.NET session state works: http://msdn.microsoft.com/en-us/library/ms972429.aspx. – Joe Mayo Dec 15 '14 at 17:02