【问题标题】:Linq2Twitter - 401 : bad authentication dataLinq2Twitter - 401:错误的身份验证数据
【发布时间】:2014-03-03 23:27:54
【问题描述】:

我一直在使用 Linq2Twitter (v. 2),使用 Search API 和 我想切换到 Stream API。我更新到 v. 3 但从那以后我不再设法进行身份验证。我不认为 Stream API 或版本可能是问题,因为我试图回到以前的版本,以前的身份验证方法,它也不再起作用了。我收到了401 : bad authentication data.

所以,这是我当前的代码:

     var auth = new SingleUserAuthorizer
          {

             CredentialStore = new SingleUserInMemoryCredentialStore()
             {
                ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"],
                ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"],
                OAuthToken = ConfigurationManager.AppSettings["twitterOAuthToken"],
                AccessToken = ConfigurationManager.AppSettings["twitterAccessToken"]
             }
           };

        TwitterContext _twitterCtx = new TwitterContext(auth);


        try
        {
            var verifyResponse =
                await
                    (from acct in _twitterCtx.Account
                     where acct.Type == AccountType.VerifyCredentials
                     select acct)
                    .SingleOrDefaultAsync();

            if (verifyResponse != null && verifyResponse.User != null)
            {
                User user = verifyResponse.User;

                Console.WriteLine(
                    "Credentials are good for {0}.",
                    user.ScreenNameResponse);
            }
        }
        catch (TwitterQueryException tqe)
        {
            Console.WriteLine(tqe.Message);
        }

当然,我检查了几次凭据,将它们打印出来。 我也尝试过 ApplicationOnlyAuthorizer、v.2、v.3,它没有任何改变。 最让我害怕的是,以前有效的(v2 + ApplicationOnly + Search API)也不起作用。

通过我的研究,我听说过由不同步的时间戳或类似问题引起的问题。但我不明白我该如何改变这一点。 该程序不在服务器上,它在本地存储。

感谢您的阅读。

【问题讨论】:

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


    【解决方案1】:

    下面是如何在 v3.0 中使用 SingleUserAuthorizer:

            var auth = new SingleUserAuthorizer
            {
                CredentialStore = new SingleUserInMemoryCredentialStore
                {
                    ConsumerKey = ConfigurationManager.AppSettings["consumerKey"],
                    ConsumerSecret = ConfigurationManager.AppSettings["consumerSecret"],
                    AccessToken = ConfigurationManager.AppSettings["accessToken"],
                    AccessTokenSecret = ConfigurationManager.AppSettings["accessTokenSecret"]
                }
            };
    

    请注意,我正在设置 AccessToken 和 AccessToken 机密。我还有一个关于解决 401 问题的常见问题解答:

    https://linqtotwitter.codeplex.com/wikipage?title=LINQ%20to%20Twitter%20FAQ&referringTitle=Documentation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-06
      • 2012-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-13
      • 2011-11-05
      • 2013-09-22
      相关资源
      最近更新 更多