LinqToTwitterDemo Save Credentials

May 24, 2011 at 9:01 PM
Edited May 24, 2011 at 9:04 PM

I can't get the credentials saving working. I [url=http://linqtotwitter.codeplex.com/discussions/237090]searched and found[/url] some pointers, but still throwing those errors.

The problem is it in the loading a new PinAuthorizer with the credentials supplied

There is something that i do wrong, but I don't see what it is. I load directly the credentials from the one that works.

It is throwing a 402 not authorized error.

I tried also to supply the UserId , UserAgent and ScreenName, but nothing gained there.

 

// validate that credentials are present
            if (string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["twitterConsumerKey"]) ||
                string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings["twitterConsumerSecret"]))
            {
                Console.WriteLine("You need to set twitterConsumerKey and twitterConsumerSecret in App.config/appSettings. Visit http://dev.twitter.com/apps for more info.\n");
                Console.Write("Press any key to exit...");
                Console.ReadKey();
                return;
            }

           

            // configure the OAuth object
            var auth = new PinAuthorizer
            {
                Credentials = new InMemoryCredentials
                {
                    ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"],
                    ConsumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"]
                },
                UseCompression = true,
                GoToTwitterAuthorization = pageLink => Process.Start(pageLink),
                GetPin = () =>
                {
                    // this executes after user authorizes, which begins with the call to auth.Authorize() below.
                    Console.WriteLine("\nAfter you authorize this application, Twitter will give you a 7-digit PIN Number.\n");
                    Console.Write("Enter the PIN number here: ");
                    return Console.ReadLine();
                }
            };
            
            // start the authorization process (launches Twitter authorization page).
            auth.Authorize();
            
            #endregion
            // reading from database simulation
            var au = new PinAuthorizer()
            {
                Credentials = new InMemoryCredentials
                {
                    ConsumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"],
                    ConsumerSecret =
                        ConfigurationManager.AppSettings["twitterConsumerSecret"]
                },
                UseCompression = true,
                GoToTwitterAuthorization = pageLink => Process.Start(pageLink),
            };

            //au.Credentials.Load(@"HARD CODED FOR TESTING");
            au.Credentials.Load(auth.Credentials.ToString());

using (var twitterCtx = new TwitterContext(auth, "https://api.twitter.com/1/", "https://search.twitter.com/"))
            {
                //Log
                twitterCtx.Log = Console.Out;
StatusDemos.Run(twitterCtx);
       }