【问题标题】:Facebook Share Dialog Deep Linking iOSFacebook 分享对话框 深度链接 iOS
【发布时间】:2015-02-20 17:11:26
【问题描述】:

我相信我已经在我的 iOS 应用上设置了所有适当的深度链接。用户可以使用 Facebook 应用程序登录我们的应用程序,如果没有的话,可以使用 Safari 登录,完成后会被正确地重定向回我们的应用程序。

当用户在原生 iOS 应用程序中点击“- 通过应用程序名称共享”时,我很难尝试实现相同的重定向。我想遵循预期的流程,如果他们没有安装应用程序,它会将用户带到 App Store,如果他们这样做,则会打开我的应用程序。目前,无论是否安装应用,用户都会被引导至应用商店。

我的 fb 应用程序的设置(由于显而易见的原因,大多数值都被混淆了)如下:

注意 在上面的图片中,大部分空白/看似空的值实际上都在那里并且是正确的,只是为了隐私而从图片中删除,这使得它们看起来 ,但它们不是。

大约 6 个月前,我在之前的应用程序上进行过这项工作,但据我了解,Facebook 已经切换到 App Links,虽然我貌似 em> 仔细阅读我能找到的关于这个主题的所有文档,我这辈子都无法让它现在工作。

我开始怀疑这是否不是我们需要在 Web 端配置的东西。现在共享的网页是否需要嵌入元标记以将用户引导到适当的位置,即页面是否需要嵌入我的应用程序的 URL 方案 - app-name://,还是什么?

从 Facebook iOS 应用上的分享重定向是否需要做一些特殊的事情,这与从 Facebook iOS 应用上的登录重定向不同?

【问题讨论】:

    标签: ios facebook-ios-sdk deep-linking facebook-share


    【解决方案1】:

    Facebook 文档非常不完整。我不得不从这个网站上删除一些信息:http://applinks.org/documentation/

    在我的应用程序中,我通过“example.com/share.php”之类的链接分享所有故事,我的 share.php 文件中的代码如下:

    <?php
        require 'Mobile_Detect.php'; //you need to download this
        $detect = new Mobile_Detect;
    
        //if user is accessing the "shared history" from the facebook website
        //it should be redirected to the website, not allowing him to browse this
        //page, as it is empty.
        //
        //the regex avoids the redirect for facebook crawler
        if (!preg_match('%facebookexternalhit/1.*%si', $_SERVER["HTTP_USER_AGENT"])) {
            if (!$detect->isiOS() && !$detect->isAndroidOS()) {
                header("Location: http://www.example.com/");
                die();
            }
        }
    
    ?><!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>App Share Page</title>
    
        <!-- This disables the intermediate web view in mobile, jumping straigt to the app -->
        <meta property="al:web:should_fallback" content="false">
    
        <!-- Android -->
        <meta property="al:android:url" content="customschemaurl://fromShare">
        <meta property="al:android:package" content="com.mycompany.myappbundleid">
        <meta property="al:android:app_name" content="App name">
    
        <!-- iOS -->
        <meta property="al:ios:url" content="customschemaurl://fromShare" />
        <meta property="al:ios:app_store_id" content="0000000" /> <!-- itunes connect app id, not bundle id -->
        <meta property="al:ios:app_name" content="App name" />
    
        <!-- OG Share (url shared) -->
        <meta property="og:title" content="some share title"/>
        <meta property="og:url" content="http://www.example.com/share.php"/>
        <meta property="og:image" content="http://www.example.com/byb-logo.png"/>
        <meta property="og:site_name" content="App name"/>
        <meta property="og:description"
              content="some description text"/>
    
    </head>
    <body>
    </body>
    </html>
    

    这个简单的网页会检测它是 android 还是 iphone 并启动应用程序,如果它是 web 浏览器(不是移动设备),它将重定向到您的网站(如果您有像我这样的多平台应用程序,可能是下载页面)并允许 facebook 爬虫(非移动)访问所需的信息以正确调用应用程序。

    希望对你有帮助。

    【讨论】:

    • 这看起来很有希望 - 我会尽快看看。谢谢!
    • 你检查了吗?
    • 我没有设法让它工作,但自从我上次查看它以来已经有一段时间了。