本文介绍了Linq 到 Twitter 状态更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码

由于某种原因,我无法更新我收到此错误的状态.

For some reason i am unable to update the status i am getting this error .

您的凭据不允许在

var tweet = twitterCtx.UpdateStatus("Hello world");

var tweet = twitterCtx.UpdateStatus("Hello world");

 var auth = new ApplicationOnlyAuthorizer
        {
            Credentials = new InMemoryCredentials
            {
               ConsumerKey = "",
               ConsumerSecret = ""
            }
        };

        auth.Authorize();
        //auth.Invalidate();
        var twitterCtx = new TwitterContext(auth);
        var tweet = twitterCtx.UpdateStatus("Hello world");

我检查了我的 ConsumerKey 和 Secret 是否正确,并且我还给了我的应用读写权限.我可以获得以前的状态,用户名,但我无法发布新状态

i checked my ConsumerKey and Secret are correct and also i gave my app read write acccess. I am able to get the previous status , User Name but i am just unable to tweet a new status

推荐答案

Application Only 授权只能执行应用级的操作.这与让您代表用户操作的其他授权人不同.逻辑是用户有帐户,但应用程序没有.因此,您不能代表应用程序发推文,因为推文无法分配到任何地方.但是,如果您代表用户发推文,则该推文会进入该用户的状态列表(他们的时间线).

Application Only authorization can only perform operations that are application-level. This differs from other authorizers that let you operate on behalf of a user. The logic is that a user has an account, but an application doesn't. Therefore, you can't tweet on behalf of an application because the tweet can't be assigned anywhere. However, if you tweet on behalf of a user, the tweet goes into that user's list of statuses (their timeline).

LINQ to Twitter 有各种授权者,您可以通过下载特定于您使用的技术的示例来查看它们的使用情况.可下载的源代码也有示例.以下是如何使用 PIN 授权方的示例:

LINQ to Twitter has various authorizers and you can see them in use by downloading samples specific to the technology you're using. The downloadable source code also has samples. Here's an example of how to use the PIN authorizer:

    static ITwitterAuthorizer DoPinOAuth()
    {
        // validate that credentials are present
        if (ConfigurationManager.AppSettings["twitterConsumerKey"].IsNullOrWhiteSpace() ||
            ConfigurationManager.AppSettings["twitterConsumerSecret"].IsNullOrWhiteSpace())
        {
            Console.WriteLine("You need to set twitterConsumerKey and twitterConsumerSecret in App.config/appSettings. Visit http://dev.twitter.com/apps for more info.\n");
            Console.Write("Press any key to exit...");
            Console.ReadKey();
            return null;
        }

        // configure the OAuth object
        var auth = new PinAuthorizer
        {
            Credentials = new InMemoryCredentials
            {
                ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"],
                ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"]
            },
            AuthAccessType = AuthAccessType.NoChange,
            UseCompression = true,
            GoToTwitterAuthorization = pageLink => Process.Start(pageLink),
            GetPin = () =>
            {
                // this executes after user authorizes, which begins with the call to auth.Authorize() below.
                Console.WriteLine("\nAfter authorizing this application, Twitter will give you a 7-digit PIN Number.\n");
                Console.Write("Enter the PIN number here: ");
                return Console.ReadLine();
            }
        };

        // start the authorization process (launches Twitter authorization page).
        auth.Authorize();
        return auth;
    }

这个方法返回一个 PinAuthorizer 的实例,auth,你可以像这样使用它:

This method returns an instance of PinAuthorizer, auth, and you can use it something like this:

PinAuthorizer auth = DoPinAuth();
var ctx = new TwitterContext(auth);
ctx.UpdateStatus("Hello LINQ to Twitter!");

* 更新 *

前面的代码来自旧版本的 LINQ to Twitter.以下是如何使用较新的异步版本执行此操作的示例:

The preceding code was from the old version of LINQ to Twitter. Here's an example of how to do it with the newer async version:

    static IAuthorizer DoPinOAuth()
    {
        var auth = new PinAuthorizer()
        {
            CredentialStore = new InMemoryCredentialStore
            {
                ConsumerKey = ConfigurationManager.AppSettings["consumerKey"],
                ConsumerSecret = ConfigurationManager.AppSettings["consumerSecret"]
            },
            GoToTwitterAuthorization = pageLink => Process.Start(pageLink),
            GetPin = () =>
            {
                Console.WriteLine(
                    "\nAfter authorizing this application, Twitter " +
                    "will give you a 7-digit PIN Number.\n");
                Console.Write("Enter the PIN number here: ");
                return Console.ReadLine();
            }
        };

        return auth;
    }

然后你可以像这样使用它:

And then you can use it like this:

        var auth = DoPinOAuth();
        await auth.AuthorizeAsync();
        var twitterCtx = new TwitterContext(auth);
        await twitterCtx.TweetAsync("Hello LINQ to Twitter!");

有关更多信息,您可以找到文档 代码.源代码在 New\Demos 文件夹中有演示.

For more information, you can find Documentation and Source code. The source code has demos in the New\Demos folder.

这篇关于Linq 到 Twitter 状态更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 22:17