Win8 -Metro app - Authorize

Sep 21, 2012 at 8:52 PM

Thanks very much for the project..very helpful.

I have Question related to re-authenticate after retrieving from DB the OAuthToken and AccessToken

Please have look at my code :

 

 

PinAuthorizer auth = null;
                    credentials cred = new Settings().getTwitterCredentials();
                    if (cred.AccessToken != null && cred.OAuthToken != null)
                    {
                        auth =
                            new PinAuthorizer
                            {
                                Credentials = new LocalDataCredentials()
                            };
                        auth.Credentials.OAuthToken = cred.OAuthToken;
                        auth.Credentials.AccessToken = cred.AccessToken;
                        auth.Credentials.ConsumerKey = "myKey";
                        auth.Credentials.ConsumerSecret = "mySecret";
                        auth.Authorize();

                    }
                    if (SuspensionManager.SessionState.ContainsKey("Authorizer"))
                    {
                        auth = SuspensionManager.SessionState["Authorizer"] as PinAuthorizer;   
                    }

                    if (auth == null || !auth.IsAuthorized)
                    {
                        page.Frame.Navigate(typeof(OAuthPage));
                        return;
                    }

                    var twitterCtx = new TwitterContext(auth);
                    
                    var favoritesResponse =
                        (from fav in twitterCtx.Favorites
                         where fav.Type == FavoritesType.Favorites
                         select fav)
                        .ToList();

it give me exception in getting the favorites ?

Coordinator
Sep 22, 2012 at 4:20 AM
Edited Sep 22, 2012 at 4:20 AM

Hi,

What is the exception message you're getting? Authentication errors often show as HTTP 401 errors.  I've written a 401 FAQ here, in case that's the cause: http://linqtotwitter.codeplex.com/wikipage?title=LINQ%20to%20Twitter%20FAQ&referringTitle=Documentation.

Joe

Sep 22, 2012 at 10:00 AM

Thanks for your reply

the exception is:

- [System.ArgumentNullException] {"consumerKey\r\nParameter name: You must provide a consumerKey."} System.ArgumentNullException

 

at the line of twitterctx.favorites

Coordinator
Sep 22, 2012 at 9:24 PM

I think I see what's happening.  Make sure LocalDataCredentials is instantiated with the correct values before assigning to Credentials property of the PinAuthorizer.  Something like this:

auth =
     new PinAuthorizer
     {
        Credentials = new LocalDataCredentials
        {
             ConsumerKey = "consumerKey",
             ConsumerSecret = "consumerSecret"
        }
     };

I still have a sequencing bug where the credentials don't get passed to dependent objects if you change them after the Authorizer is constructed.  Here's my blog post on one way to do this in Windows 8:

http://geekswithblogs.net/WinAZ/archive/2012/07/02/using-linq-to-twitter-oauth-with-windows-8.aspx

BTW, my latest bit of code includes a WinRtAuthorizer.  I haven't documented or blogged about it yet, but it's very nice.

Joe

Coordinator
Sep 22, 2012 at 9:25 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.