Application Only Authentication

Apr 12, 2013 at 10:21 AM
How do I do Application only authentication using LinqToTwitter.
For more details https://dev.twitter.com/docs/auth/application-only-auth
Coordinator
Apr 13, 2013 at 3:27 AM
Hi,

I have an example in the OAuthAuthorizersDemo.cs file in the LinqToTwitterDemos project in the downloadable source code. Here's how it works:
            var auth = new ApplicationOnlyAuthorizer
            {
                Credentials = new InMemoryCredentials
                {
                    ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"],
                    ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"]
                }
            };

            auth.Authorize();
            //auth.Invalidate();

            var twitterCtx = new TwitterContext(auth);

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

            Console.WriteLine("\nQuery: {0}\n", srch.SearchMetaData.Query);
            srch.Statuses.ForEach(entry =>
                Console.WriteLine(
                    "ID: {0, -15}, Source: {1}\nContent: {2}\n",
                    entry.StatusID, entry.Source, entry.Text));
You can re-use the bearer token as long as it's valid. You can call Invalidate (commented in the code) to invalidate the bearer token, but will need to re-authorize to get a new bearer token.

@JoeMayo
Apr 13, 2013 at 10:41 AM
How do I check how long is the bearer token Valid? In other words, how does one know when the bearer token gets invalidated and then how to re validate it or request for new bearer token?
Sent from Windows Mail
From: JoeMayo
Sent: ‎Saturday‎, ‎13‎ ‎April‎ ‎2013 ‎10‎:‎46
To: [email removed]

From: JoeMayo

Hi,

I have an example in the OAuthAuthorizersDemo.cs file in the LinqToTwitterDemos project in the downloadable source code. Here's how it works:
            var auth = new ApplicationOnlyAuthorizer
            {
                Credentials = new InMemoryCredentials
                {
                    ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"],
                    ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"]
                }
            };

            auth.Authorize();
            //auth.Invalidate();

            var twitterCtx = new TwitterContext(auth);

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

            Console.WriteLine("\nQuery: {0}\n", srch.SearchMetaData.Query);
            srch.Statuses.ForEach(entry =>
                Console.WriteLine(
                    "ID: {0, -15}, Source: {1}\nContent: {2}\n",
                    entry.StatusID, entry.Source, entry.Text));
You can re-use the bearer token as long as it's valid. You can call Invalidate (commented in the code) to invalidate the bearer token, but will need to re-authorize to get a new bearer token.

@JoeMayo
Coordinator
Apr 13, 2013 at 8:27 PM
I asked that question as soon as Twitter announced it. Here's their response:

https://dev.twitter.com/discussions/15744

@JoeMayo
Mar 4 at 5:39 PM
Is there a demo available of the ApplicationOnlyAuthorizer scenario that works with the most recent version of linq to twitter?
Coordinator
Mar 4 at 6:09 PM
Hi amcintire,

Yes, look at the Linq2TwitterDemos_Console project in the downloadable source code.

@JoeMayo