Facebook 登录按钮:iOS 上 Chrome 错误的解决方法

Posted

技术标签:

【中文标题】Facebook 登录按钮:iOS 上 Chrome 错误的解决方法【英文标题】:Facebook Login Button: Workaround for bug of Chrome on iOS 【发布时间】:2012-11-28 11:09:35 【问题描述】:

目前,我正在尝试解决登录 Facebook Developer 的错误: https://developers.facebook.com/bugs/325086340912814/

我正在使用带有 Facebook C# SDK 和 Facebook javascript SDK 的 ASP.NET MVC 3。

这里是javascript代码:

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- data-max-rows="1" data-scope="email"></div>

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

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");
        
    

【问题讨论】:

【参考方案1】:

通过使用 Facebook 身份验证重定向解决。

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

【讨论】:

以上是关于Facebook 登录按钮:iOS 上 Chrome 错误的解决方法的主要内容,如果未能解决你的问题,请参考以下文章

Facebook IOS SDK登录按钮强制小文本

Facebook 登录在某些 iOS 设备上总是出错

与 iOS 应用程序集成的 Facebook 登录页面间歇性关闭

Facebook 登录按钮对齐 iOS

ios Facebook 登录按钮 - 不会更改为注销

作为 iOS 上 FaceBook 身份验证的一部分登录我们的网站