0

I have a string like this one (it's the response from the Facebook login dialog):

msft-{ProductID}://authorize/?access_token={user-access-token}&expires_in={expiration-time-of-token}

And I need to get the value of the access_token variable.

It's the same issue already answered here: Get url parameters from a string in .NET , but unfortunately the HttpUtility doesn't exist in Windows phone 8.1 runtime. Is there an alternative to HttpUtility.ParseQueryString?

Community
  • 1
  • 1
the_nuts
  • 5,634
  • 1
  • 36
  • 68

2 Answers2

2

From MSDN page http://msdn.microsoft.com/en-us/library/windows/apps/hh825884.aspx:

Use the WwwFormUrlDecoder class to break a query string into name-value pairs, based on the number and placement of "&" symbols. Each name-value pair is represented by an IWwwFormUrlDecoderEntry object.

Art Dumas
  • 440
  • 1
  • 5
  • 12
0

One easy way is to use Regular Expression. This should work:

        var regex = new System.Text.RegularExpressions.Regex("[?&]access_token(?:=(?<token>[^&]*))?");

        var match = regex.Match (responseString);

        if (match.Success)
        {
            Console.WriteLine (match.Groups["token"]);
        }
SKall
  • 5,234
  • 1
  • 16
  • 25