如何检查用户是否有 Facebook 时间线?
我想仅为具有“publish_actions”权限和时间轴的用户启用某些功能。如何检测用户是否启用了时间轴?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我想仅为具有“publish_actions”权限和时间轴的用户启用某些功能。如何检测用户是否启用了时间轴?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
目前没有 API 方法来检查用户是否启用了时间线。
您可以尝试使用“添加到时间线(测试版)”社交插件< /a> (将
publish_actions
作为perms
传递)与 Facebook JS-SDK 事件。订阅
auth.login
、auth.authResponseChange
和/或auth.statusChange
事件并检查status
属性code>response 传递给事件监听器,一旦事件触发并且用户连接
,您可以发布操作,如果成功,则将用户标记为已安装时间线的用户。然而,这也有一些缺点:
publish_actions
,以确保他们拥有时间线和授予的权限。Currently there is no API way to check if user have enabled timeline.
You can try to use "Add To Timeline (beta)" social plugin (passing
publish_actions
asperms
) in combination with Facebook JS-SDK Events.Subscribe to
auth.login
,auth.authResponseChange
and/orauth.statusChange
events and checkstatus
property ofresponse
passed to event listener, once event fired and user isconnected
you can publish action and if succeed mark user as one who have timeline installed.This however have some downsides:
publish_actions
in flows other than "Add To Timeline" social plugin to be sure they are have both timeline and permission granted.1)部分解决方案是检查用户是否有名为“封面照片”的相册。虽然不是所有但大多数激活时间线的用户都会拥有这张专辑!
2)一个可靠的方法是实际检索用户个人资料的 html 内容并检查它是否有时间线!
1) A partial solution is to check if user has a album named "cover photos". Although not all but MOST users who would have activated timeline would have this album!!
2) A sure way is to actually retrieve html contents of a user's profile and check if it has a timeline!!
最终(可能在不久的将来)每个人的个人资料都将转移到时间轴,因此 Facebook 似乎没有提供可靠的方法来检测启用时间轴的应用程序。
Eventually (likely in the near future) everyone's profile will be rolled over to Timeline, so it would seem facebook has not provided a reliable way to detect a timeline-enabled app.
以下潜在解决方案不需要额外的权限请求。如果您在隐藏的 DIV 中添加 Facebook 时间轴插件代码,您可以等到 FB Canvas 完成加载(或网页中的 xfbml)并测试该元素的 CSS 高度。如果用户没有时间轴,它将是 0px。否则,它将是 250px(因为我已将其包括在内)。 这仅适用于 Facebook 应用程序(不适用于 Facebook 集成网页):
如果用户未通过将元素样式高度设置为 0 来激活时间轴,Facebook 会隐藏此插件元素。
将其添加到您的应用程序页面:
然后,在您的 javascript 中(这里使用 jQuery,仅供参考):
由于潜在的网络延迟,以下 Web 集成 的可靠性稍差,但可以将概念修改为一些可行的解决方案:
由于 FB.Canvas .setDoneLoading 未被调用包含 FB 集成的网站,修改上面的 FB.Canvas.setDoneLoading 函数以订阅 xfbml.render 操作并在测试上设置超时:
window.fbAsyncInit = function () {
FB.init({ ... }); // 在你的 FB.init 代码之后
};
我在测试中发现将 FB.Event.subscribe('xfbml.render', 移动到 $(document).ready(function() { ... }) ; 当您的应用程序嵌入 Facebook 页面时有助于解决延迟问题(加载时间稍长),因此它可能会也可能不会经受进一步的测试。
The following potential solution requires no additional permissions request. If you add the Facebook timeline plugin code within a concealed DIV you can wait until after the FB Canvas is done loading (or xfbml in web pages) and test the CSS height of that element. If the user does not have Timeline it will be 0px. Otherwise, it will be 250px (as I've included it). This only works within Facebook Apps (not in Facebook integrate web pages):
Facebook hides this plugin element if the user has not activated timeline by setting the element style height to 0.
Add this to your App page:
Then, in your javascript (this use jQuery, FYI):
The following for Web Integration is somewhat less reliable due to potential network latency, but the concept could be modified to some workable solution:
Since FB.Canvas.setDoneLoading is not called on a website that includes FB integration, modify the FB.Canvas.setDoneLoading function above to subscribe to the xfbml.render action and put a timeout on the test:
window.fbAsyncInit = function () {
FB.init({ ... }); // after your FB.init code
};
I've found in my testing that moving the FB.Event.subscribe('xfbml.render', into a $(document).ready(function() { ... }); helps with latency when your app is embedded in a Facebook page (takes a little longer to load). Just started testing this out, so it may or may not hold up to further testing.