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

13

我需要实现Twitter API应用程序授权,并且已经查阅了linq2twitter oauth示例和stackoverflow的问题,但是我没有找到有关此方面的有用信息。

请问是否可以使用linq2twitter来实现这种授权,如何操作?

1个回答

22
当然可以。这里有一个例子:
        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("\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));

下载源代码后,LinqToTwitterDemo项目中有运行示例。Program.cs文件有一个仅应用程序的选项。还有一个OAuthDemos.cs文件带有一个示例。


哦,我只是在寻找OAout的例子:( 非常感谢!那对我很有用! - Festys.rpo
Joe,即使已调用Authorize()并成功返回TwitterData,Auth.IsAuthorized始终返回false。我该如何可靠地知道应用程序何时被授权?我发现如果在每次调用中调用Authorize(),则会在Linq2Twitter中出现未捕获的异常。 - DevDave
我刚在这里回答了一个类似的问题:http://stackoverflow.com/questions/16520278/linqtotwitter-isauthorized-always-returns-false-for-applicationonlyauthorizer/16528192#16528192 - Joe Mayo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接