Facebook登录按钮:iOS上的Chrome错误的解决方法 [英] Facebook Login Button: Workaround for bug of Chrome on iOS

查看:148
本文介绍了Facebook登录按钮:iOS上的Chrome错误的解决方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我正在尝试解决Facebook开发人员中记录的错误: https://developers.facebook.com/bugs/325086340912814/

Currently, I am trying to solve a bug logged in Facebook Developer: https://developers.facebook.com/bugs/325086340912814/

我正在将ASP.NET MVC 3与Facebook C#SDK和Facebook Javascript SDK结合使用.

I am using ASP.NET MVC 3 with Facebook C# SDK and Facebook Javascript SDK.

这是JavaScript代码:

Here is javascript code:

window.fbAsyncInit = function () {
// init the FB JS SDK
FB.init({
    appId: '298365513556623', // App ID from the App Dashboard
    channelUrl: 'http://www.christianinfoportal.com/channel.html', // Channel File for x-domain communication
    status: true, // check the login status upon init?
    cookie: true, // set sessions cookies to allow your server to access the session?
    xfbml: true  // parse XFBML tags on this page?
});

// Additional initialization code such as adding Event Listeners goes here
FB.Event.subscribe('auth.authResponseChange', function (response) {
    if ((response.status == 'connected')) {
        if (fbIgnoreFirstEventFire)
            fbIgnoreFirstEventFire = false;
        else {
            // the user is logged in and has authenticated your
            // app, and response.authResponse supplies
            // the user's ID, a valid access token, a signed
            // request, and the time the access token 
            // and signed request each expire
            var uid = response.authResponse.userID;
            var accessToken = response.authResponse.accessToken;

            // TODO: Handle the access token
            // Do a post to the server to finish the logon
            // This is a form post since we don't want to use AJAX
            var form = document.createElement("form");
            form.setAttribute("method", 'post');
            form.setAttribute("action", '/FBLogin');

            var field = document.createElement("input");
            field.setAttribute("type", "hidden");
            field.setAttribute("name", 'accessToken');
            field.setAttribute("value", accessToken);
            form.appendChild(field);

            var field = document.createElement("input");
            field.setAttribute("type", "hidden");
            field.setAttribute("name", 'returnUrl');
            field.setAttribute("value", window.location.href);
            form.appendChild(field);

            document.body.appendChild(form);
            form.submit();
        }
    } else if (response.status == 'not_authorized') {
        // the user is logged in to Facebook, 
        // but has not authenticated your app
    } else {
        // the user isn't logged in to Facebook.
    }
    });
};

// Load the SDK's source Asynchronously
(function (d, debug) {
    var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
    if (d.getElementById(id)) { return; }
    js = d.createElement('script'); js.id = id; js.async = true;
    js.src = "//connect.facebook.net/en_US/all" + (debug ? "/debug" : "") + ".js";
    ref.parentNode.insertBefore(js, ref);
}(document, /*debug*/ false));

查看代码非常简单:

<div id="fbLoginButton" class="fb-login-button" data-show-faces="false" data-width="50" data-max-rows="1" data-scope="email"></div>

我基本上将访问令牌转发到服务器端代码页:

I basically forward the access token to a server side code page:

public ActionResult FBLogin(String returnUrl)
    {
        var accessToken = Request["accessToken"];

        //FB fires even without the user clicking the Log In button
        Session["FBLoginFirstClick"] = true;

        //Session["AccessToken"] = accessToken;

        //this.lblAccessToken.Text = accessToken;
        //Response.Redirect("/MyUrlHere");

        var client = new Facebook.FacebookClient(accessToken);
        dynamic me = client.Get("me");

        String email, fullName;
        fullName = me.first_name + " " + me.last_name;
        email = me.email;

        Models.User.ThirdPartyLogin(email, fullName, Session);

        if (!string.IsNullOrEmpty(returnUrl))
        {
            return Redirect(returnUrl);
        }
        else
        {
            return RedirectToAction("Index", "Home");
        }
    }

推荐答案

使用Facebook身份验证重定向解决.

Solved by using Facebook authentication redirect.

https://developers.facebook.com /docs/facebook-login/manually-build-a-login-flow/

这篇关于Facebook登录按钮:iOS上的Chrome错误的解决方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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