在 Facebook 的“Send Dialog”文档中,它指出:
This dialog can be used with the JavaScript SDK and by performing a full redirect to a URL. It is not supported on mobile devices.
发送对话框(当它工作时)正是我想要使用的(因为它默认发送给特定的人):
作为备用,您可以使用“Share Button”,但共享按钮的用户流程略有不同(您必须选择将其发送给特定的人):
现在我正在使用 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>
有谁知道 Facebook 使用的标准(这样我就可以触发正确的回退)?
最佳答案
显然,“不支持移动设备”确实意味着它不能在移动设备上运行。
因此,如果您不需要在移动端实现“发送”API,那么您可以嗅探 User-Agent 以检查它是否是桌面端。
您可能想阅读 Browser detection using the user agent .
你可以尝试这样的事情:
if (navigator.userAgent.indexOf("Mobi") > -1){
//do your thing here
}
我创建了以下示例来确认它是否有效。为了测试 facebook API 是否使用大小来“区分”移动设备,我在全屏和比手机更小的宽度和高度尺寸下尝试了 Chrome 和 Firefox。为了测试移动设备,我使用了 Red Hat JBoss Developer Studio 中的 Bowser SIM 功能针对以下(垂直和水平方向):Samsung Galaxy S3、Samsung 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>
以下是我在移动环境中使用“发送”API 的尝试。
Facebook SDK 不是开源的,但 FacebookJS 代码是。最初在审查 FacebookJS source 之后和文档我认为短语“移动设备不支持”并不意味着它在移动设备上被阻止。这仅意味着他们没有像为“共享”所做的那样构建漂亮的移动版本。
这让我想到您可以在提交“发送”的 HTML5/jQuery Mobile 表单中使用 URL 重定向选项。至少那是我会尝试的。 ;)
然而
在尝试实现上述想法后,我发现无法在任何移动设备上显示“发送”对话框,因为 facebook API 读取用户代理并将您从“www.facebook”站点重定向到“m.facebook”。
Facebook 上有几张关于这件事的票。
Send dialog is not working on mobile device
Send Dialog Doesn't Work on Mobile Web
Send dialog broken for mobile devices
您可以使用 Send API 中的 URL 重定向示例 URL 对此进行测试并将其输入手机浏览器。
虽然我不推荐,但可以从服务器端更改 User-Agent 并在之后重定向 URL。请注意,您必须从服务器端执行此操作,因为出于安全原因,您无法从浏览器中更改此设置。正如我所说,这是 hack,你应该只作为最后的手段尝试。有几篇与此相关的帖子:
Want to load desktop version in my webview using uastring
关于javascript - Facebook 对 'supported mobile devices' 的标准是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20079949/
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我有一个模型:classItem项目有一个属性“商店”基于存储的值,我希望Item对象对特定方法具有不同的行为。Rails中是否有针对此的通用设计模式?如果方法中没有大的if-else语句,这是如何干净利落地完成的? 最佳答案 通常通过Single-TableInheritance. 关于ruby-on-rails-Rails-子类化模型的设计模式是什么?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.co
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
为什么4.1%2返回0.0999999999999996?但是4.2%2==0.2。 最佳答案 参见此处:WhatEveryProgrammerShouldKnowAboutFloating-PointArithmetic实数是无限的。计算机使用的位数有限(今天是32位、64位)。因此计算机进行的浮点运算不能代表所有的实数。0.1是这些数字之一。请注意,这不是与Ruby相关的问题,而是与所有编程语言相关的问题,因为它来自计算机表示实数的方式。 关于ruby-为什么4.1%2使用Ruby返
我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer
在MRIRuby中我可以这样做:deftransferinternal_server=self.init_serverpid=forkdointernal_server.runend#Maketheserverprocessrunindependently.Process.detach(pid)internal_client=self.init_client#Dootherstuffwithconnectingtointernal_server...internal_client.post('somedata')ensure#KillserverProcess.kill('KILL',
我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby1.9+ 关于ruby-主要:Objectwhenrun