Question

I have been working with Linq2Twitter (v. 2), using the Search API and I wanted to switch to the Stream API. I updated to v. 3 but since then I don't manage to authenticate anymore. I don't think the Stream API or the version could be the problem, because I've tried to go back to the previous version, previous authentication methods, and it doesn't work anymore either. I get a 401 : bad authentication data.

So, here is my current code :

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

Of course, I checked the credentials several times, printed them out and all. I tried with ApplicationOnlyAuthorizer, v.2, v.3 as well, it doesn't change anything. What scares me the most is that what used to work (v2 + ApplicationOnly + Search API) doesn't work either.

Through my research I've heard of a problem caused by unsynchronized timestamps, or something like that. But I don't understand how I can change that. The program is not on a server, it's locally stored.

Thank you for reading.

Was it helpful?

Solution

Here's how to use SingleUserAuthorizer in v3.0:

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

Notice here that I'm setting AccessToken and AccessToken secret. I also have a FAQ with suggestions for resolving 401 problems:

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top