Festys.rpo Festys.rpo - 3 years ago 247
ASP.NET (C#) Question

Twitter API application-only authentication (with linq2twitter)

I need to implement Twitter API application-only authentication and I've searched through linq2twitter oauth samples and stackoverflow questions, but I didn't find anything helpful about it.

Is it possible to implement this kind of authorization with linq2twitter and how?

Answer Source

Sure is. Here's an example:

        var auth = new ApplicationOnlyAuthorizer
            CredentialStore = new InMemoryCredentialStore()
                ConsumerKey = "twitterConsumerKey",
                ConsumerSecret = "twitterConsumerSecret"


        var twitterCtx = new TwitterContext(auth);

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

        Console.WriteLine("\nQuery: {0}\n", srch.SearchMetaData.Query);
        srch.Statuses.ForEach(entry =>
                "ID: {0, -15}, Source: {1}\nContent: {2}\n",
                entry.StatusID, entry.Source, entry.Text));

There are running examples in the LinqToTwitterDemo project of the downloadable source code. The Program.cs file has an option for Application Only. There's also an OAuthDemos.cs file that has an example.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download