This project has moved and is read-only. For the latest updates, please go here.

Implementing Single User Authorization

Single User Authorization is designed for scenarios where you'll only ever have one account accessing Twitter. i.e. if your Web site does periodic Twitter updates, regardless of user or you have a server that monitors general information. You can obtain all four Single User Credentials from your application page at

To get started, you'll need to instantiate a SingleUserAuthorizer. Credentials must be populated with ConsumerKey, ConsumerSecret, AccessToken, and AccessTokenSecret which identify both your application and the user to Twitter. Heres how you can instantiate an authorizer:

    var auth = new SingleUserAuthorizer
        CredentialStore = new SingleUserInMemoryCredentialStore
            ConsumerKey = ConfigurationManager.AppSettings["consumerKey"],
            ConsumerSecret = ConfigurationManager.AppSettings["consumerSecret"],
            AccessToken = ConfigurationManager.AppSettings["accessToken"],
            AccessTokenSecret = ConfigurationManager.AppSettings["accessTokenSecret"]
The example above instantiates a SingleUserAuthorizer with an SingleUserInMemoryCredentialStore, which is an implementation of ICredentialStore. The credentials are being read from a config file, which is fine because they generally don't change for your application. The config file looks like this:
    <!-- Fill in your consumer key and secret here to make the OAuth sample work. -->
    <!-- Twitter sign-up: -->
    <add key="consumerKey" value="YourConsumerKey"/>
    <add key="consumerSecret" value="YourConsumerSecret"/>
    <add key="accessToken" value="AccessTokenFromTwitterAppPage"/>
    <add key="accessTokenSecret" value="AccessTokenSecretFromTwitterAppPage"/>

Unlike other authorizers, you don't need to authorize your application. Just instantiate a TwitterContext with the authorizer and use it like this:

            var twitterCtx = new TwitterContext(auth);

            var searchResponse =
                (from search in twitterCtx.Search
                 where search.Type == SearchType.Search &&
                       search.Query == "\"LINQ to Twitter\""
                 select search)

            if (searchResponse != null && searchResponse.Statuses != null)
                searchResponse.Statuses.ForEach(tweet =>
                        "User: {0}, Tweet: {1}", 
You now have a TwitterContext instance that has been properly authorized and can see how to use it to make queries.
The SingleUserAuthorizer allows you to fill in all of your credentials at one time, bypassing the user-centric authorization process. The process is less involved than with other authorizers, such as PinAuthorizer or MvcAuthorizer, because the process only involves instantiating the authorizer and then assigning the authorizer to a TwitterContext instance.

Last edited Nov 29, 2013 at 7:49 PM by JoeMayo, version 7