Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
116 views
Welcome To Ask or Share your Answers For Others

1 Answer

Sure is. Here's an example:

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

        await auth.AuthorizeAsync();

        var twitterCtx = new TwitterContext(auth);

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

        Console.WriteLine("
Query: {0}
", srch.SearchMetaData.Query);
        srch.Statuses.ForEach(entry =>
            Console.WriteLine(
                "ID: {0, -15}, Source: {1}
Content: {2}
",
                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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...