how to use oAuth for sign-in with twitter

Oct 21, 2013 at 10:15 AM
Hi everyone. First of all thank you for this library. I'm new in twitter api so if the question is a basic sorry for that.

I want to get twitter id who uses my application so I decided to add a sing in with twitter button. I thought that I need to use oAuth for that. But I couldn't find how to use oAuth with tweetinvi in example project.
Oct 21, 2013 at 10:52 AM
Edited Oct 21, 2013 at 11:49 AM
Hi there,

I am quite not sure what you are willing to do.
The TokenCreator class manages the different steps a user requires to perform in order to accept your application with Twitter.
When the user has validated the requirements (entering the captcha on the twitter website) the TokenCreator will give you a Token that contains TokenCredentials.

You can store (look at Twitter conditions to learn what you can and cannot store) this information wherever you want.
If you are willing to store the User Id specifically you use the example called "GenerateToken".

Here is the example to meet your request :
public static void StoreUserId(long userId)
    // You code to store it

public static void GenerateTokenAndSaveUserId(IToken consumerToken)
    // Starting Token Generation...
    ITokenCreator creator = new TokenCreator(consumerToken.ConsumerKey,

    Console.WriteLine("Please enter the verifier key...");
    IToken newToken = creator.CreateToken(GetCaptchaFromConsole);

    if (newToken != null)
        Console.WriteLine("Token generated!");
        ITokenUser loggedUser = new TokenUser(newToken);

public static int GetCaptchaFromConsole(string validationUrl)
    Console.WriteLine("Please visit :");
    Console.WriteLine("{0}", validationUrl);
    Console.WriteLine("\nEnter validation key : ");
    string validationKey = Console.ReadLine();

    int result;
    if (Int32.TryParse(validationKey, out result))
        return result;

    return -1;
Please have a look to this example and let me know if this helps you.

Kind regards,
Oct 21, 2013 at 2:32 PM
Yes, that's what I want but I'm working on web application. Is there any example for web app ?
Oct 21, 2013 at 2:47 PM
Edited Oct 21, 2013 at 2:55 PM

I cannot provide example in ASP as I currently have not worked with ASP on Tweetinvi.
Though I know Tweetinvi is already used to create ASP solutions.

The only thing you have to do is keep this logic and move this logic in your controller (if you are using MVC).
Otherwise you can do this in your asp page using :
      //  Same code logic 
Everything should almost be identical but the way you get the captcha.

If you need a better understanding of how Token are generated please read this:

If you need a better understanding on the TokenUser (user logged) please read this:

Please keep me up to date.

Oct 23, 2013 at 7:55 AM
Actually I asked how to make validate without captcha. But I think, I need a callback url for this process and I don't have any real host. I'll make this with captcha for now. Thank you for your help and advice Linvi.
Oct 23, 2013 at 10:34 AM
Sorry I did not understand your question.

URL redirection is not currently implemented within Tweetinvi. It is already part of the tasks for the release.

Kind Regards,