Umar Khan
Umar Khan

Reputation: 11

LinqToTwitter.TwitterQueryException: Bad Authentication Data

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!

Upvotes: 0

Views: 439

Answers (1)

Jaap
Jaap

Reputation: 745

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

Upvotes: 1

Related Questions