0

Hi I've gone through the official LinqToTwitter docs. I'm using single user authorization to get all tweets. But still getting "Bad Authentication" exception. What's wrong in the code?

 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();
     }

My app.config file :

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

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

Your help is much appreciated!

Umar Khan
  • 1
  • 1

1 Answers1

1

You can try this:

  • Double check your Twitter credentials (keys/tokens) at http://apps.twitter.com

  • Check if your keys/tokens vars getting filled with the right values from ConfigurationManager.AppSettings, otherwise use (for testing purposes only) ConsumerKey = "YourConsumerKeyFromTwitter". Do this for all 4 variables

  • Use the latest .Net Framework

Jaap
  • 665
  • 1
  • 8
  • 19
  • 2
    Oh, and Joe Mayo's Faq on authentication gives you much more info. See: https://github.com/JoeMayo/LinqToTwitter/wiki/LINQ-to-Twitter-FAQ – Jaap May 30 '18 at 10:31