Twitter API 仅应用程序身份验证(使用 linq2twitter)

编程入门 行业动态 更新时间:2024-10-23 09:35:58
本文介绍了Twitter API 仅应用程序身份验证(使用 linq2twitter)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要实现 Twitter API 仅应用程序身份验证,我已经搜索了 linq2twitter oauth 示例 和 stackoverflow 问题,但我没有发现任何有用的信息.

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.

是否可以通过 linq2twitter 实现这种授权?如何实现?

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

推荐答案

当然可以.举个例子:

        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));

可下载源代码的LinqToTwitterDemo项目中有运行示例.Program.cs 文件有一个仅应用程序"选项.还有一个包含示例的 OAuthDemos.cs 文件.

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.

这篇关于Twitter API 仅应用程序身份验证(使用 linq2twitter)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-03-31 16:52:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/808796.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   身份验证   Twitter   API   linq2twitter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!