Twitter API 仅应用程序身份验证(使用 linq2twitter) [英] Twitter API application-only authentication (with linq2twitter)

查看:45
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆