JS Facebook登录iOS8

2024-05-03

我的 facebook 应用程序上的登录按钮在 iOS 8 中完全停止工作。我以为这是我所做的事情,但是当我从他们的网站获取 facebook 示例 html 并将其应用到我的页面时,它仍然不起作用(我的应用程序 ID 已被替换)与 xxxxx)。基本上,弹出窗口会打开进行 Facebook 身份验证,但永远不会关闭并返回到我的应用程序。我只是留下一个空白,打开哪个选项卡:

<!DOCTYPE html>
<html>
<head>
    <title>Facebook Login JavaScript Example</title>
    <meta charset="UTF-8">
</head>
<body>
    <script>
        // This is called with the results from from FB.getLoginStatus().
        function statusChangeCallback(response) {
            console.log('statusChangeCallback');
            console.log(response);
            // The response object is returned with a status field that lets the
            // app know the current login status of the person.
            // Full docs on the response object can be found in the documentation
            // for FB.getLoginStatus().
            if (response.status === 'connected') {
                // Logged into your app and Facebook.
                testAPI();
            } else if (response.status === 'not_authorized') {
                // The person is logged into Facebook, but not your app.
                document.getElementById('status').innerHTML = 'Please log ' +
                  'into this app.';
            } else {
                // The person is not logged into Facebook, so we're not sure if
                // they are logged into this app or not.
                document.getElementById('status').innerHTML = 'Please log ' +
                  'into Facebook.';
            }
        }

        // This function is called when someone finishes with the Login
        // Button.  See the onlogin handler attached to it in the sample
        // code below.
        function checkLoginState() {
            FB.getLoginStatus(function (response) {
                statusChangeCallback(response);
            });
        }

        window.fbAsyncInit = function () {
            FB.init({
                appId: 'xxxxxxxxxxxxx',
                cookie: true,  // enable cookies to allow the server to access
                // the session
                xfbml: true,  // parse social plugins on this page
                version: 'v2.1' // use version 2.1
            });

            // Now that we've initialized the JavaScript SDK, we call
            // FB.getLoginStatus().  This function gets the state of the
            // person visiting this page and can return one of three states to
            // the callback you provide.  They can be:
            //
            // 1. Logged into your app ('connected')
            // 2. Logged into Facebook, but not your app ('not_authorized')
            // 3. Not logged into Facebook and can't tell if they are logged into
            //    your app or not.
            //
            // These three cases are handled in the callback function.

            FB.getLoginStatus(function (response) {
                statusChangeCallback(response);
            });

        };

        // Load the SDK asynchronously
        (function (d, s, id) {
            var js, fjs = d.getElementsByTagName(s)[0];
            if (d.getElementById(id)) return;
            js = d.createElement(s); js.id = id;
            js.src = "//connect.facebook.net/en_US/sdk.js";
            fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));

        // Here we run a very simple test of the Graph API after login is
        // successful.  See statusChangeCallback() for when this call is made.
        function testAPI() {
            console.log('Welcome!  Fetching your information.... ');
            FB.api('/me', function (response) {
                console.log('Successful login for: ' + response.name);
                document.getElementById('status').innerHTML =
                  'Thanks for logging in, ' + response.name + '!';
            });
        }
    </script>
    <!--
      Below we include the Login Button social plugin. This button uses
      the JavaScript SDK to present a graphical Login button that triggers
      the FB.login() function when clicked.
    -->

    <fb:login-button scope="public_profile,email" onlogin="checkLoginState();">
    </fb:login-button>

    <div id="status">
    </div>

</body>
</html>

我想到的唯一解决方案是在 iOS 上使用完全重定向时降级回服务器端身份验证流程。基本上你的应用程序应该点击这样的 URL:

https://www.facebook.com/dialog/oauth?
    client_id={app-id}
   &redirect_uri={redirect-uri}

这在桌面上是一种不和谐的体验,但在移动设备上可以说是一种更好的体验,因为用户不会经历奇怪的选项卡切换(这首先是新问题的根源)。要仅在 iOS 上降级到此流程,请确保您的登录链接实际上是 Facebook 身份验证对话框的 href(如上面的链接,或者对于 Rails 上的omniauth 用户来说,是“/auth/facebook”)。然后将调用客户端流程的 JavaScript 封装在代码中,以防止其在 iOS(或所有移动设备,如果您愿意)上运行。

if(!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
[Facebook client side flow code here]
}

(如果有人有更优雅的方法,请在评论中告诉我)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

JS Facebook登录iOS8 的相关文章

随机推荐

  • 带数据注释的枚举类型的 Json.NET 自定义序列化

    我想序列化一个枚举类型 以便它返回一个数组 其中枚举作为对象 其中包含 值 名称 和数据注释值 我需要序列化方面的帮助 这是我到目前为止所做的 枚举 public enum Status Display Name Active status
  • 如何获取UIImage的大小(KB)

    我从以下位置获取图像didFinishPickingMediaWithInfo UIImage originalImage UIImage info valueForKey UIImagePickerControllerOriginalIm
  • Gatsby 在 graphql 查询返回后获取图像路径

    所以我用 Gatsby 和 Remark 写了一个博客网站 我的帖子结构如下 Library category name article name index md 这非常有效 使我能够制作类似的路径 category name artic
  • Tesseract OCR 将削减的 0 混淆为 8

    我已经在终点字体上训练了 tesseract 但无论如何 我都无法让它识别 0 我正在使用 jTessEditor 创建训练 tif 和框 即使在验证时 它也会将所有 0 读取为 8 我有什么遗漏的吗 下面是 0 的示例 它将其读作 8 我
  • 为 Pipenv 提供不同的源或 git url 以进行生产和开发

    我们正在使用Pipenv https github com pypa pipenv and Pipfiles https github com pypa pipfile用于管理我们的 Python 包需求 我们使用私有 GitLab 服务器
  • Azure Nvidia 中的 apt-update 出现公钥错误

    我在 AZURE 上启动了 NVIDIA VM 并尝试使用进行更新sudo apt update但给出错误 Hit 2 http azure archive ubuntu com ubuntu focal InRelease Hit 3 h
  • uninitialized_copy memcpy/memmove 优化

    我最近开始研究 MSVC 实现中的 STL 那里有一些不错的技巧 但是我不知道为什么使用以下标准 The std uninitialized copy被优化为一个简单的memcpy memmove如果满足某些条件 据我了解 输入范围可以是m
  • 带有子列表的干净架构 toJson(reso 编码器)

    我正在尝试使用干净的架构 由 reso 编码器解释 https resocoder com 2019 09 09 flutter tdd clean architecture course 4 data layer overview mod
  • python round 留下尾随 0 [重复]

    这个问题在这里已经有答案了 我正在尝试将 python 中的浮点数四舍五入到小数点后零位 然而 round 方法每次都会留下尾随 0 value 10 01 rounded value round value print rounded v
  • API 级别 15 的印地语字体(又名 Android 4.0.2)

    我有一个基于印地语内容的 Android 应用程序 并使用了 Android API 16 SDK 中的 devangiri 字体 并重命名为印地语 ttf 文本在 API 级别 16 和 17 上渲染良好 但在 Android API 级
  • Unity3D:在 AA 解析后绘制粒子以提高性能

    我正在尝试评估 MSAA 对 Unity 中含有大量粒子的场景的影响 为此 我需要 使用 8x MSAA 绘制场景中的所有非粒子对象 使用上一个通道中解析的深度缓冲区来渲染所有 将非遮挡粒子系统转移到较小的渲染目标上 将 2 的颜色缓冲区与
  • 如何使用 Gmail 帐户对 Android 中的应用程序进行身份验证?

    在 android 中 我如何通过 Gmail 帐户对用户进行身份验证 他们有适用于 android 的 api 或支持吗 谢谢 是的 您可以在 Android 中使用 OAuth 有一篇帖子对此说的很详细 Android 中使用适用于 J
  • 在 OpenGL ES 1.1 中将多个纹理绑定到一个网格

    如果我有一个网格 例如有 6 个面的立方体 每个面分别由 4 个顶点组成 总共 24 个顶点 并且我想对每个面应用不同的纹理 我该怎么做 目前 我使用 glDrawElements 一次绘制整个网格 立方体的所有 6 个面 将所有索引提供到
  • 如何获取magento中登录客户的订单列表

    我正在努力获取客户订购的订单号 名称 列表 我尝试过使用 Mage getModel sales order gt load order id 但对我不起作用 实际上 我正在开发帮助台模块并尝试将订单分配给票证 好的朋友 感谢您的提示 我通
  • cv2.imread:检查图像是否正在被读取

    我正在用 python 编写一个 OpenCV 程序 在某些时候我有类似的东西 import cv2 import numpy as np img cv2 imread myImage jpg do stuff with image her
  • 在 iOS8 中使用 UISearchBar 启用取消按钮

    有什么方法可以启用 UISearchBar 的 取消 按钮吗 现在 每当我致电辞职第一响应者时 取消按钮都会被禁用 仅当我再次点击搜索栏时 取消才会启用 有没有办法停止禁用取消按钮 这是适用于 iOS 8 和 Swift 的可行解决方案 f
  • 单击浏览器后退按钮时,将用户带回到他们在上一页滚动到的位置

    当用户按下浏览器中的后退按钮时 是否可以将用户带回到他们向下滚动到的页面区域 如 pageA 是屏幕大小的两倍 因此您必须滚动才能阅读更多内容 您单击 pageA 上的链接转到新页面 pageB 阅读后 您在浏览器中单击 返回 现在 当您返
  • 如何使用 OpenCV 找到红色区域? [复制]

    这个问题在这里已经有答案了 我正在尝试编写一个检测红色的程序 然而有时它比平常更暗 所以我不能只使用一个值 检测不同深浅的红色的最佳范围是多少 我目前使用的范围是 128 0 0 255 60 60 但有时它甚至检测不到我放在它前面的红色物
  • UIScreen 屏幕始终返回 1 个屏幕

    我正在尝试在不使用镜像模式的情况下通过 Airplay 在 Apple TV 上显示图片 但当镜像关闭时 UIScreen Screens 方法始终返回 1 个屏幕 主屏幕 我希望我的图片显示与照片应用程序相同 Airplay 无需镜像 N
  • JS Facebook登录iOS8

    我的 facebook 应用程序上的登录按钮在 iOS 8 中完全停止工作 我以为这是我所做的事情 但是当我从他们的网站获取 facebook 示例 html 并将其应用到我的页面时 它仍然不起作用 我的应用程序 ID 已被替换 与 xxx