Facebook .NET客户端SDK是否支持通过AppStudio生成的通用应用程序/应用程序?

Gab*_*bor 2 .net c# facebook facebook-c#-sdk windows-phone-8.1

我通过微软的AppStudio创建了一个通用应用程序.我尝试按照"美味教程"(http://facebooksdk.net/docs/phone/tutorial/)向应用添加Facebook身份验证.

当我在手机上运行应用程序时,我永远无法进入Facebook登录页面,因为以下行: await App.FacebookSessionClient.LoginAsync("user_about_me,read_stream");

总是会导致以下异常:

System.NotImplementedException: Not implemented
at Windows.Security.Authentication.Web.WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions options, Uri requestUri, Uri callbackUri) at Facebook.Client.FacebookSessionClient.d__24.MoveNext()

异常的来源是FacebookSessionClient.cs(facebook-client包)中的这个调用: var result = await WebAuthenticationBroker.AuthenticateAsync(options, startUri, endUri);

似乎这个功能没有为手机实现.我仍然想知道如何使用完全相同的代码的turial可行.

Ale*_*aev 7

它尚未实现8.1.如果要在8.1中使用Facebook身份验证,可以使用以下方法:

在您的App类中:

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);
}
Run Code Online (Sandbox Code Playgroud)

我把所有东西放在一个地方只是为了示例目的,最好分开fb身份验证逻辑.你可以在这里找到这种方法MSDN Windows Phone 8.1 Web身份验证示例