Generate Credential Examples

Mar 3, 2014 at 5:51 AM
I am trying to get GenerateCredentialExamples working from the example program but GetAuthorizationURLForCallback always returns null.
Mar 3, 2014 at 11:10 AM

Have you verified that you have set a callback URL in Twitter Application Settings (on

Mar 12, 2014 at 2:50 PM
I am having an issue with this as well. I have confirmed that my callback URL in the Twitter Application Settings is correct.

I have tried the methods in code that return IOAuthCredentials, including GetAuthorizationURLForCallback() and the examples in the cheat sheet, but no success. I've confirmed that twitter is sending me back oauth_token and oauth_verifier values.

Are there other things / settings that we should be checking for to get this working?
Mar 12, 2014 at 3:11 PM
Could you please share your code so that I identify where the issue could come from.

Mar 12, 2014 at 3:20 PM
Here are a couple of ways I've tried. I am using version This is the page that Twitter calls back after authorization. I've confirmed that twitter is sending me back oauth_token and oauth_verifier values. Each time, the newCredentials object is null.
var applicationCredentials = CredentialsCreator.GenerateApplicationCredentials("MyTwitterConsumerKey", "MyTwitterConsumerSecret");
var newCredentials = CredentialsCreator.GetCredentialsFromCallbackURL(HttpContext.Current.Request.Url.AbsoluteUri, applicationCredentials);
var oauthVerifier = string.Empty + Request.QueryString["oauth_verifier"];
var applicationCredentials = CredentialsCreator.GenerateApplicationCredentials("MyTwitterConsumerKey", "MyTwitterConsumerSecret");
var newCredentials = CredentialsCreator.GetCredentialsFromVerifierCode(oauthVerifier, applicationCredentials);
Mar 12, 2014 at 3:41 PM
Edited Mar 12, 2014 at 3:45 PM
I have everything working perfectly on my side using the code provided on Examplinvi/CheatSheet.
// I think we are fine on this line
var applicationCredentials = CredentialsCreator.GenerateApplicationCredentials(consumerKey, consumerSecret);

// I receive an url that I need to redirect to in order for twitter to ask me whether I want to accept the application
// Example :
var url = CredentialsCreator.GetAuthorizationURLForCallback(applicationCredentials, "");

// When I redirect to this URL Twitter ask me to accept the application.
// When I accept, Twitter redirects to the CallbackURL
// Example :

// At this point I have all the information I need
var callbackURL = "";

// I get the new credentials.
var newCredentials = CredentialsCreator.GetCredentialsFromCallbackURL(callbackURL, applicationCredentials);
I understand with your second example that you probably have been able to get as far as the last line of the application.
At this point would you please give me the complete Request URL?

Have you followed this workflow or did you forgot to redirect correctly or maybe did not specify the right callbackURL at the end of the process?

Mar 12, 2014 at 4:32 PM
Thanks for the quick reply. I am doing this from a web application. The process detailed above is exactly what I'm doing, except I have it split into two parts: The first part I do until I get the authorization URL, at which point I forward the user to that page, and the second page is the callback URL redirected from Twitter.

I'm going to send you more details to you directly so that I'm not posting sensitive info. If you see any issues, please let me know.
Apr 2, 2014 at 4:26 AM

I have exactly the same problem. Everytime it gives to me null value.

This is for a web application and I am doing just like amcintire. There is no way I can get anything but null.

[NullReferenceException: Object reference not set to an instance of an object.]
TweetinviCore.Extensions.StringFormater.UrlEncode(String str) +470
TweetinviWebLogic.OAuthWebRequestGenerator.GenerateParameter(String key, String value, Boolean requiredForSignature, Boolean requiredForHeader, Boolean isPartOfOAuthSecretKey) +77
TweetinviCredentials.CredentialsCreator.GetCredentialsFromVerifierCode(String verifierCode, ITemporaryCredentials temporaryCredentials) +172
Tweetinvi.CredentialsCreator.GetCredentialsFromVerifierCode(String verifierCode, ITemporaryCredentials temporaryCredentials) +109
NuevoCliente.vtoken() in c:\pages\pages\WebApp\NuevoCliente.aspx.cs:58
NuevoCliente.Page_Load(Object sender, EventArgs e) in c:\pages\pages\WebApp\NuevoCliente.aspx.cs:23
System.Web.UI.Control.LoadRecursive() +70
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3177
Apr 2, 2014 at 10:18 AM

From my reading of the code I would say that the verifier code you provided to the verifier code is null.
Also, I am not quite sure why you use the verifier code solution instead of the callback.

Could you please send the code where you are trying to perform the login logic so that I can help you more?

Apr 6, 2014 at 11:18 PM
Hi Linvi,

i'm building a POC using Tweetinvi and i'm facing a particular situation here.

Context: ASP.NET MVC application, with 2 actions
        public ActionResult TwitterLogin_Begin() {

            var applicationCredentials = CredentialsCreator.GenerateApplicationCredentials(_apiKey, _apiSecret);
            var url = CredentialsCreator.GetAuthorizationURLForCallback(applicationCredentials, "http://localhost:52393/TwitterLogin_Complete/");

            return Redirect(url);

        public ActionResult TwitterLogin_Complete(string oauth_token, string oauth_verifier) {

            var applicationCredentials = CredentialsCreator.GenerateApplicationCredentials(_apiKey, _apiSecret);

            string _url = Request.Url.AbsoluteUri;     // http://localhost:52393/TwitterLogin_Complete/oauth_token=xxxxx&oauth_verifier=yyyyy

            var newCredentials = CredentialsCreator.GetCredentialsFromCallbackURL(_url, applicationCredentials);

            string _accessToken = newCredentials.AccessToken;
            string _accessTokenSecret = newCredentials.AccessTokenSecret;
The action "TwitterLogin_Begin" works just fine, and the action "TwitterLogin_Complete" receives oauth_token and oauth_verifier correctly. The problem is with the "newCredentials" variable... no matter what i do, it's always NULL.

Any idea, comment or suggestion?

Thanks in advanced,

Apr 7, 2014 at 12:15 AM
Hi Pablo,

As you can see you are not the first one to have the problem but I have never been able to reproduce it.
Would you be able to send me your code as well as oauth credentials on my personal contact page in order to allow me diagnose the problem.

As always, I will use your credentials only in the context of helping you solve this issue.

Apr 7, 2014 at 12:32 AM
Hi Linvi,

what information do you need exactly, API keys?


Apr 7, 2014 at 1:08 AM
Edited Apr 7, 2014 at 1:10 AM

I would need your code and an API key that I can use to log in to your application.
Also would you please try to not use localhost, Twitter generally restrict the use of the localhost for the credentials creation.

Before sending me any credential, please try the example provided in the response of this post (green post), leave the url being but change the application credentials to be yours.

I am heading to bed, it is quite late here, I will catch up tomorrow.

Apr 7, 2014 at 11:23 PM

Some update on the subject will be appreciated so that I can try to understand if something is going wrong with the API.

Apr 7, 2014 at 11:48 PM
Hi Linvi,

i have a few updates:

1.- i've tried your code (green answer) and after enter my USR and PWD on Twitter i got redirected to with an oauth_token and oauth_verifier. I'm having the exact same result using the code i sent yesterday, so the callback is working fine.

2.- Tried not to use "localhost". I've changed it to and same results, callback works but i can't get an AccessToken (oauth_token and oauth_verifier, YES)

3.- i also changed the "Callback URL" at the app settings page on Twitter (there is no need to do this for version 1.0a, but tried anyway) and didn't work.

4.- i've tried the sign-in with another Twitter account, and results were the same, didn't work.

So, my only problem is with this line:

// I get the new credentials.
var newCredentials = CredentialsCreator.GetCredentialsFromCallbackURL(callbackURL, applicationCredentials);

newCredentials is always NULL.

Have you tried what i sent?


Apr 11, 2014 at 1:05 PM
Hello Everyone,

I have a workaround to this problem, I am using tweetinvi into my project and also stuck into into this problem as well.

First of all sorry for my english.

1.Using Below code to redirect user to twitter:-

var applicationCredentials = CredentialsCreator.GenerateApplicationCredentials(ConsumerKey, ConsumerSecret);
var url = CredentialsCreator.GetAuthorizationURLForCallback(applicationCredentials, HttpContext.Current.Request.Url.AbsoluteUri);
//Saving applicationCredentials into session for using them later.
Session["authkey"] = applicationCredentials.AuthorizationKey;
Session["authSecret"] = applicationCredentials.AuthorizationSecret;
  1. Using Below code for getting newcredentials on page load:-
        if (Request.QueryString["oauth_verifier"] != null)
            var callbackURL = HttpContext.Current.Request.Url.AbsoluteUri;
            var applicationCredentials = CredentialsCreator.GenerateApplicationCredentials(ConsumerKey, ConsumerSecret);
            //Setting applicationCredentials to the previous one i saved in sessions.
            applicationCredentials.AuthorizationKey = Session["authkey"].ToString();
            applicationCredentials.AuthorizationSecret = Session["authSecret"].ToString();
            // Here we provide the entire URL where the user has been redirected
            var newCredentials = CredentialsCreator.GetCredentialsFromVerifierCode(Request.QueryString["oauth_verifier"].ToString(), applicationCredentials);
            if (newCredentials != null)
                //use your credentials here newCredentials.AccessToken, newCredentials.AccessTokenSecret
Marked as answer by linvi on 4/11/2014 at 8:04 AM
Apr 11, 2014 at 2:03 PM
I can confirm that aru2man's response is the solution, please mark his as the correct answer. In a web context, we need to be saving the AuthorizationKey and AuthorizationSecret before we redirect the user off to Twitter.
Apr 11, 2014 at 10:47 PM
Yes, you're right, aru2man's answer solved the problem, thank you both.
Dec 23, 2014 at 2:32 AM
What if the application is Window Store App, and HttpContext does not exist, so the HttpContext.Current.Request.Url.AbsoluteUri will not work.
I am really confused for the CallBackURL when it is not web application.

What should I do?