【问题标题】:401 when attempting to Tweet with Linq to Twitter尝试使用 Linq 向 Twitter 发送推文时出现 401
【发布时间】:2013-04-02 03:11:21
【问题描述】:

因此,我查看了 Linq 到 Twitter 文档中关于 Oauth 的 401 状态的所有建议,老实说,我不知道自己做错了什么。

var auth = new PinAuthorizer
        {
            Credentials = new InMemoryCredentials
            {
                ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"],
                ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"],
                //OAuthToken = ConfigurationManager.AppSettings["twitterOAuthToken"], //don't include this 
                //AccessToken = ConfigurationManager.AppSettings["twitterAccessToken"] //or this for new users. 
            },
            //
            UseCompression = true,
            GoToTwitterAuthorization = pageLink => Process.Start(pageLink),
            GetPin = () =>
                {
                    Console.WriteLine("/nAfter twitter authorizes your application you will be returned here or something/n");
                    Console.Write("Enter Pin here:");
                    return Console.ReadLine();
                }

        };

        auth.Authorize();


        using (var twitterCtx = new TwitterContext(auth, "https://api.twitter.com/1/",
            "https://search.twitter.com/"))
        {

            try
            {
                twitterCtx.Log = Console.Out;
                Console.WriteLine("Please provide tweet text");
                string tweet = Console.ReadLine();

                twitterCtx.UpdateStatus(tweet);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }


        }

我已经使用 Pin 身份验证方法以及单用户方法(通过配置文件提供 oauth 密钥)运行了这个。我可以查询推文,但我无法更新我的状态或发送直接消息(我在尝试 DM 时收到 403 禁止)。我提供了一个回调 URL(虽然是假的),所以我想不出为什么这不起作用。任何帮助将不胜感激。

PS 这在 Main 中运行,不确定是否重要

【问题讨论】:

    标签: c# twitter-oauth linq-to-twitter


    【解决方案1】:

    您所需要的只是 TwitterContext ctor 的重载,它将使用正确的基本 URL:

    new TwitterContext(auth)
    

    您使用的示例用于 v1.0 URL,LINQ to Twitter 现在在 Twitter API v1.1 上。它将默认为正确的基本 URL。

    如果您查询正常,但在更新和 DM 时出现错误,请仔细检查以确保您没有尝试发布相同的文本。这就是为什么我将 DateTime.Now 附加到测试推文的末尾 - 以保证唯一性。

    【讨论】:

    • 你太棒了,非常感谢。有用。除了这个混乱之外,我真的很喜欢 Linq to Twitter。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2013-06-21
    • 2011-11-07
    • 1970-01-01
    • 2017-02-18
    • 2022-11-19
    • 1970-01-01
    • 2016-03-18
    • 1970-01-01
    相关资源
    最近更新 更多