什么是"支持移动设备"的Facebook标准

Jas*_*ske 5 javascript facebook

在Facebook的" 发送对话框 " 的文档中,它指出:

此对话框可与JavaScript SDK一起使用,也可以执行完全重定向到URL.移动设备不支持此功能.

发送对话框(当它工作时)正是我想要使用的(因为它默认发送给特定的人):

发送对话框

作为后备,您可以使用" 共享按钮 ",但共享按钮的用户流略有不同(您必须选择将其发送给特定人员):

分享按钮

现在我正在使用Zurb Foundation的Visibility Classes来触发显示哪个按钮,如下所示:

<button id='actionShare' class='button large-12 hide-for-touch'>share on facebook</button>
<a href='https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fwww.nytimes.com%2F2011%2F06%2F15%2Farts%2Fpeople-argue-just-to-win-scholars-assert.html' class='button small-12 show-for-touch' target='_blank'>share on facebook</a>

<script>
  $('#actionShare').on('click', function() {
    FB.ui({
      method: 'send',
      link: window.location.href
    });
  });
</script>
Run Code Online (Sandbox Code Playgroud)

有谁知道Facebook使用的标准(所以我可以触发正确的后备)?

Jos*_*son 10

显然,"移动设备不支持",确实意味着它无法在移动设备上运行.

因此,如果您不需要在移动端实施"发送"API,那么您可以嗅探用户代理以检查它是否是桌面.

您可能希望使用用户代理读取浏览器检测.

你可能会尝试这样的事情:

    if (navigator.userAgent.indexOf("Mobi") > -1){
         //do your thing here
    }
Run Code Online (Sandbox Code Playgroud)

我创建了以下示例以确认这是有效的.为了测试facebook API是否使用大小来"区分"移动设备,我尝试了全屏和小屏幕的Chrome和Firefox,然后是宽度和高度尺寸的手机.为了测试移动设备,我使用红帽JBoss开发者工作室中的Bowser SIM功能来解决以下问题(垂直和水平方向):三星Galaxy S3,三星Galaxy Note 10.1,IPhone 4和5以及IPad 4 Retina.

结论是嗅探UA工作!

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
    <script type="text/javascript">
    $( document ).ready( function() {
        $("#button-1").click(function(event) {
            if (navigator.userAgent.indexOf("Mobi") > -1){
                window.location.assign("#page-2");
            } else {
                window.location.replace("https://www.facebook.com/dialog/send?" + 
                                        "app_id=123050457758183" + 
                                        "&link=http://www.nytimes.com/2011/06/15/arts/people-argue-just-to-win-scholars-assert.html" + 
                                        "&redirect_uri=https://www.bancsabadell.com/cs/Satellite/SabAtl/" 
                );
            }
        });
    })
    </script>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
    // init the FB JS SDK
    FB.init({
      appId      : '123050457758183',                    // App ID from the app dashboard
      status     : true,                                 // Check Facebook Login status
      xfbml      : true                                  // Look for social plugins on the page
    });

    // Additional initialization code such as adding Event Listeners goes here
  };

  // 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/all.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));</script>

<div data-role="page" id="page-1" data-theme="b">
    <div data-role="header" data-theme="b">
        <h1>Try to Send.</h1>
    </div>
    <div data-role="content">
        <a href="#" id="button-1" data-role="button" data-theme="b">Send</a>
    </div>
</div>

<div data-role="page" id="page-2" data-theme="b">
    <div data-role="header" data-theme="b">
        <h1>Share</h1>
    </div>
    <div data-role="content">
        <div class="fb-share-button" data-href="http://developers.facebook.com/docs/plugins/" data-type="button_count"></div>
    </div>
</div>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

以下是我尝试在移动环境中使用"发送"API.

Facebook SDK不是开源,但FacebookJS代码是.最初在审查了FacebookJS来源和文档后,我认为"移动设备不支持"这一短语并不意味着它在移动设备上被阻止.这只意味着他们没有像"共享"那样建立一个漂亮的漂亮移动版本.

这让我觉得你可以在提交"发送"的HTML5/jQuery Mobile表单中使用URL Redirect选项.至少这是我会尝试的.;)

然而

在尝试实现上述想法后,我发现无法在任何移动设备上显示"发送"对话框,因为facebook API读取用户代理并将您从"www.facebook"站点重定向到"m.facebook" ".

关于这件事,在facebook上有几张门票.

发送对话框无法在移动设备上运行

发送对话框在移动网络上不起作用

发送移动设备的发送对话框

您可以使用Send API中的URL重定向示例URL 并在手机浏览器中输入它来对此进行测试.

https://www.facebook.com/dialog/send?app_id=123050457758183&link=http://www.nytimes.com/2011/06/15/arts/people-argue-just-to-win-scholars-assert. HTML&REDIRECT_URI = HTTPS://www.bancsabadell.com/cs/Satellite/SabAtl/

虽然我不建议这样做,但有可能从服务器端更改User-Agent并在此之后重定向URL.请注意,您必须从服务器端执行此操作,因为出于安全原因,您无法在浏览器中更改此设置.正如我所说,这是黑客,你应该只作为最后的手段.有几个与此相关的帖子:

想要使用uastring在我的webview中加载桌面版本

强制webview显示桌面站点

设置WebView以查看桌面站点和非移动站点