LinqToTwitter.TwitterQueryException:错误的身份验证数据

时间:2018-05-20 09:45:45

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

您好我已经浏览了官方的LinqToTwitter文档。我使用单用户授权来获取所有推文。但仍然得到" Bad Authentication"例外。代码中有什么问题?

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




        var twitterContext = new TwitterContext(auth);

           var searchResponse =
                 await
                 (from search in twitterContext.Search
                  where search.Type == SearchType.Search &&
                        search.Query == "\"Donald Trump\""
                  select search)
                 .SingleOrDefaultAsync();

            if (searchResponse != null && searchResponse.Statuses != null)
            {
                searchResponse.Statuses.ForEach(tweet =>
                    Console.WriteLine(
                        "User: {0}, Tweet: {1}",
                        tweet.User.ScreenNameResponse,
                        tweet.Text));
            }



    }
    public MainWindow()
    {
        InitializeComponent();
        GetRecentTweets();
     }

我的app.config文件:

<?xml version="1.0" encoding="utf-8" ?>

                                  

<startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>

非常感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

你可以试试这个:

  • http://apps.twitter.com

  • 仔细检查您的Twitter凭据(密钥/令牌)
  • 检查您的密钥/令牌变量是否从ConfigurationManager.AppSettings中填入正确的值,否则使用(仅用于测试目的)ConsumerKey =“YourConsumerKeyFromTwitter”。对所有4个变量执行此操作

  • 使用最新的.Net Framework