Reputation: 6054
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?
Upvotes: 0
Views: 1640
Reputation: 440
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.
Upvotes: 2
Reputation: 5234
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"]);
}
Upvotes: 0