为了使用WebAuthenticationBroker(微软的WinRT登录库),我必须将协议设置为ms-app://,当我从Web浏览器调用它时,它可以正常工作。
在WinRT应用程序中调用时,通过WebAuthenticationBroker我收到协议错误(422)。
有没有人成功完成这项工作?
一些示例代码非常非常有用:)
这是我们的代码:(我们的密钥由---------代替)
String URL = "https://soundcloud.com/connect?client_id=" + Uri.EscapeDataString("-----------------------------") +
"&redirect_uri=" + Uri.EscapeDataString("ms-app://rewritez") +
"&response_type=code&scope=" + Uri.EscapeDataString("non-expiring");
string url = URL;
Uri startUri = new Uri(url);
Uri endUri = new Uri("https://api.soundcloud.com/oauth2/token?");
try
{
WebAuthenticationResult webAuthenticationResult =
await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.UseTitle, startUri, endUri);
if (webAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success)
{
string token = webAuthenticationResult.ResponseData;
// now you have the token
}
else if (webAuthenticationResult.ResponseStatus == WebAuthenticationStatus.ErrorHttp)
{
// do something when the request failed
}
else
{
// do something when an unknown error occurred
}
}
catch (Exception ex)
{
int i = 43; // statement here just so we can set a breakpoint for debuggin
// do something when an exception occurred
}