This project has moved and is read-only. For the latest updates, please go here.

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";

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

                    if (auth == null || !auth.IsAuthorized)

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

it give me exception in getting the favorites ?

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


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:


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

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:

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


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.