为了使用 WebAuthenticationBroker(Microsoft 的 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
}