Does the Facebook .NET client SDK support universal apps / apps generated via AppStudio?

被刻印的时光 ゝ 提交于 2019-12-01 00:30:15

It's not implemented for 8.1 yet. If you want to use Facebook authentication in 8.1 you can use the following approach:

In your App class:

private const string RedirectUrl = "https://www.facebook.com/connect/login_success.html";
private static readonly IReadOnlyCollection<string> Permissions = new[] { "email", "offline_access" };

protected override void OnActivated(IActivatedEventArgs args)
{
    base.OnActivated(args);
    var continuationActivatedEventArgs = args as IContinuationActivatedEventArgs;
    if (continuationActivatedEventArgs == null)
        return;
    var webAuthenticationResult = ((WebAuthenticationBrokerContinuationEventArgs)continuationActivatedEventArgs).WebAuthenticationResult;
    if (webAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success)
    {
        var facebookClient = new FacebookClient();
        var result = facebookClient.ParseOAuthCallbackUrl(new Uri(webAuthenticationResult.ResponseData));
        if (!result.IsSuccess)
        {
            // Process unsuccessful authentication
        }
        else
        {
            // Process successful authentication
            var accessToken = result.AccessToken;
        }
    }
}

// Authentication method, this method should be invoked when you click Facebook authentication button
public void AuthenticateAndContinue()
{
    var loginUrl = GetLoginUrl();
    WebAuthenticationBroker.AuthenticateAndContinue(loginUrl, new Uri(RedirectUrl));
}

private Uri GetLoginUrl()
{
    var parameters = new Dictionary<string, object>();
    parameters["client_id"] = "YourFacebookApplicationId";
    parameters["redirect_uri"] = RedirectUrl;
    parameters["response_type"] = "token";
    parameters["display"] = "touch";
    parameters["mobile"] = true;
    parameters["scope"] = String.Join(",", Permissions);

    var facebookClient = new FacebookClient();

    return facebookClient.GetLoginUrl(parameters);
}

I put everything in one place just for example purposes, it's better to separate fb authentication logic. You can find this approach here MSDN Windows Phone 8.1 Web Authentication samples

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!