Facebook登录 - Windows 10 UWP - 桌面

时间:2015-10-13 08:52:14

标签: facebook facebook-graph-api facebook-c#-sdk windows-10 uwp

我正在构建一个新的通用Windows 10 UWP应用程序,并试图进行Facebook登录。

在Facebook上,我已将应用的Windows应用部分设置为具有我应用的标识符:

  

Windows:s-1-15-xxxxxxxxxxxx
  Windows Phone:fef49b712e5a843cbfeb0c9d780423fc(不是实际的)

在包清单文件中,我添加了以下协议:

  

MSFT-fef49b712e5a843cbfeb0c9d780423fc

这意味着我将redirect_uri参数设置为:

  

MSFT-fef49b712e5a843cbfeb0c9d780423fc://授权

在手机上运行时(使用Windows 10 Mobile Preview),该服务运行正常,它会在手机上打开Facebook应用程序(使用fbconnect:// authorize?.....),然后进行身份验证,然后打开我的应用程序 - 完美!!

但是,在桌面上尝试相同时,它不起作用。在我的Launcher.LaunchUriAsync()中设置了标准Facebook网络对话框https://www.facebook.com/dialog/oauth?....的后备Uri。) - 这是因为没有支持登录的Windows 10 Facebook应用程序。

将相同的redirect_uri发送到Facebook,它会打开Web浏览器(Edge)并请求权限等。一旦授予权限,就不会发生任何事情。似乎协议处理不起作用。

任何想法都会有用。

2 个答案:

答案 0 :(得分:6)

在桌面设备上,请尝试使用WebAuthenticationBroker代替Launcher.LaunchUriAsync,如下例所示:http://dotnetbyexample.blogspot.de/2015/06/custom-oauth-login-to-facebook-for.html

private async Task<string> AuthenticateFacebookAsync()
{
  try
  {
    var fb = new FacebookClient();

    var redirectUri = 
      WebAuthenticationBroker.GetCurrentApplicationCallbackUri().ToString();

    var loginUri = fb.GetLoginUrl(new
                                   {
                                     client_id = AppId,
                                     redirect_uri = redirectUri,
                                     scope = ExtendedPermissions,
                                     display = "popup",
                                     response_type = "token"
                                   });

    var callbackUri = new Uri(redirectUri, UriKind.Absolute);

    var authenticationResult =
      await
        WebAuthenticationBroker.AuthenticateAsync(
        WebAuthenticationOptions.None, 
        loginUri, callbackUri);

    return ParseAuthenticationResult(fb, authenticationResult);
  }
  catch (Exception ex)
  {
    return ex.Message;
  }
}

答案 1 :(得分:2)

$.each()用于redirect_uri。

在facebook开发者控制台中更新相同的uri。

https://developers.facebook.com/apps//settings/

Facebook developer console

相关问题