Verifing Credentials question

Apr 28, 2014 at 5:02 PM
I'm having some issue authorizing twitter on the application of mine.

Here is what my authorization code looks like
        public Uri CreateOptInUrl(string redirectUri)
            var applicationCredentials = CredentialsCreator.GenerateApplicationCredentials(Settings.ApiKey, Settings.ApiSecret);
            var url = CredentialsCreator.GetAuthorizationURLForCallback(applicationCredentials, redirectUri);

            return new Uri(url);
the issue comes when I return to my application and my callback code fires:
        public IExternalApp HandleOptInResponse(HttpRequestBase request, string redirectUri)
                IExternalApp app = new ExternalApp {ExternalAppType = ExternalAppType.Twitter};

                var data = request.Params;

                var applicationCredentials = CredentialsCreator.GenerateApplicationCredentials(Settings.ApiKey, Settings.ApiSecret);

                var verifyAuth = CredentialsCreator.GetCredentialsFromVerifierCode(data["oauth_verifier"], applicationCredentials);

                var usr = Tweetinvi.User.GetLoggedUser();
                app.Uid = usr.Id;
                app.Token = verifyAuth.AccessToken;
                app.TokenSecret = verifyAuth.AccessTokenSecret;
                app.Username = usr.ScreenName;
                app.Name = usr.Name;

                return app;
                return null;
verifyAuth come back as null which usr then is null.

I'm hoping someone can help me as I already tried another 3rd party client and this is starting to anger me.

Apr 28, 2014 at 5:43 PM

I assume you are currently using tweetinvi from an ASP application.
If so, please read the following post:
Use the solution marked as answer.

The problem comes from the fact that even static credentials are not shared between different sessions of ASP and consequently you lose the previous application credentials.
As Tweetinvi relies on these credentials to continue the sign in process you need to set them a second time.

I am here to help so please feel free to ask any question. I will answer at the end of my working day.

Apr 28, 2014 at 7:07 PM
Edited Apr 28, 2014 at 8:19 PM
I am using it on a MVC 5 project.

using sessions may be a hard thing to use as the twitter code is in another layer that is all business logic.
Apr 28, 2014 at 8:26 PM

At some point, you need to store the credentials information somewhere. So that you ensure that your credentials are always up to date and not cleanup by a new session.

Marked as answer by linvi on 4/29/2014 at 7:55 AM
Apr 29, 2014 at 2:22 PM
I did some looking and its possible my isue is that AuthorizationKey & AuthorizationSecret are null. did I miss a step?
Apr 29, 2014 at 2:39 PM
I see that I missed a step, once I can find a way to keep the one values in play, I'll report back.
Apr 29, 2014 at 3:10 PM
I got it working, the issue was I didn't setup the access token and access secret.
Apr 29, 2014 at 3:54 PM
Sorry for the time I took to reply, I am quite busy.
Thank you for your feedback. And please know that if you have any issue the forum is open and I will always reply.