难道Facebook的.NET客户端SDK支持通用的应用程序/应用程序通过AppStudio产生的? [英] Does the Facebook .NET client SDK support universal apps / apps generated via AppStudio?

查看:274
本文介绍了难道Facebook的.NET客户端SDK支持通用的应用程序/应用程序通过AppStudio产生的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建通过微软的AppStudio一个通用的应用程序。 我试图继美味教程,并称Facebook的身份验证的应用程序( http://facebooksdk.net/文档/手机/教程/ )。

I created a universal app via Microsoft's AppStudio. I tried adding Facebook authentication to the app by following the 'Scrumptious tutorial' (http://facebooksdk.net/docs/phone/tutorial/).

当我跑我的手机上的应用程序,我永远不能给Facebook登录页面,因为下面一行:等待App.FacebookSessionClient.LoginAsync(user_about_me,read_stream);

When I run the app on my phone, I can never get to the facebook login page, because the following line: await App.FacebookSessionClient.LoginAsync("user_about_me,read_stream");

始终会导致以下异常:

System.NotImplementedException:未实现
       在Windows.Security.Authentication.Web.WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions选项​​,乌里requestUri,乌里callbackUri)        在Facebook.Client.FacebookSessionClient.d__24.MoveNext()

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的客户端软件包的): VAR的结果=等待WebAuthenticationBroker.AuthenticateAsync(选项,startUri,endUri);

The source of the exception is this call in the FacebookSessionClient.cs (facebook-client package): var result = await WebAuthenticationBroker.AuthenticateAsync(options, startUri, endUri);

看来,这个功能是不是为手机实现。我仍然不知道它是如何可能的turial,它指的是完全相同的code会的工作。

It seems that this function is not implemented for the phone. I am still wondering how it is possible that the turial, which refers to the exact same code would work.

推荐答案

这不是8.1实现的呢。如果你想在8.1使用Facebook的身份验证,你可以使用下面的方法:

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

在你的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);
}

我把一切都放在一个地方,只是作为一个例子,这是更好地分离FB身份验证逻辑。 你可以在这里找到这种方法 MSDN的Windows Phone 8.1 Web认证样品

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

这篇关于难道Facebook的.NET客户端SDK支持通用的应用程序/应用程序通过AppStudio产生的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆