如何检查用户是否有 Facebook 时间线?

发布于 2024-12-22 00:33:42 字数 61 浏览 1 评论 0 原文

我想仅为具有“publish_actions”权限和时间轴的用户启用某些功能。如何检测用户是否启用了时间轴?

I want to enable certain features only for users with the "publish_actions" permission and Timeline. How can I detect if the user enabled Timeline?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

萧瑟寒风 2024-12-29 00:33:42

目前没有 API 方法来检查用户是否启用了时间线。

您可以尝试使用“添加到时间线(测试版)”社交插件< /a> (将 publish_actions 作为 perms 传递)与 Facebook JS-SDK 事件

订阅 auth.loginauth.authResponseChange 和/或 auth.statusChange 事件并检查 status 属性code>response 传递给事件监听器,一旦事件触发并且用户连接,您可以发布操作,如果成功,则将用户标记为已安装时间线的用户。

然而,这也有一些缺点:

  • 最好不要在“添加到时间线”社交插件之外的流程中向用户询问 publish_actions,以确保他们拥有时间线和授予的权限。
  • 您应该发布操作以确保他们已授予执行此操作的权限,因为这些事件可以是其他用户操作(例如密码更改或 Facebook 用户切换等)。

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 as perms) in combination with Facebook JS-SDK Events.

Subscribe to auth.login, auth.authResponseChange and/or auth.statusChange events and check status property of response passed to event listener, once event fired and user is connected you can publish action and if succeed mark user as one who have timeline installed.

This however have some downsides:

  • Better be sure not to ask users for publish_actions in flows other than "Add To Timeline" social plugin to be sure they are have both timeline and permission granted.
  • You should be publishing action to ensure that they have granted permissions to do so, since those events can be other user actions (like password change or Facebook user switching, etc...).
另类 2024-12-29 00:33:42

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!!

盛夏已如深秋| 2024-12-29 00:33:42

最终(可能在不久的将来)每个人的个人资料都将转移到时间轴,因此 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.

幻梦 2024-12-29 00:33:42

以下潜在解决方案不需要额外的权限请求。如果您在隐藏的 DIV 中添加 Facebook 时间轴插件代码,您可以等到 FB Canvas 完成加载(或网页中的 xfbml)并测试该元素的 CSS 高度。如果用户没有时间轴,它将是 0px。否则,它将是 250px(因为我已将其包括在内)。 这仅适用于 Facebook 应用程序(不适用于 Facebook 集成网页)

如果用户未通过将元素样式高度设置为 0 来激活时间轴,Facebook 会隐藏此插件元素。

将其添加到您的应用程序页面:

<div id="timeline-hidden" style="display:none">
  <div class="fb-add-to-timeline" data-show-faces="true"></div>
</div>
<div id="timeline-test"></div>

然后,在您的 javascript 中(这里使用 jQuery,仅供参考):

window.fbAsyncInit = function () {
FB.init({ ... }); // after your FB.init code

    FB.Canvas.setDoneLoading(
  function (result) {

    var str_timeline;
    var tlsrc = $("#timeline-hidden").find("iframe").first().css("height");

    if("0px"==tlsrc)
        str_timeline = '<h2 style="color:red">This user DOES NOT have timeline.<h2>';
    else
        str_timeline = "<h2>This user DOES have timeline.</h2>";

    $("#timeline-test").html(str_timeline + ", timeline plugin css height:" + tlsrc + ", loadtime: " + result.time_delta_ms);
  }
);

};

由于潜在的网络延迟,以下 Web 集成 的可靠性稍差,但可以将概念修改为一些可行的解决方案:

由于 FB.Canvas .setDoneLoading 未被调用包含 FB 集成的网站,修改上面的 FB.Canvas.setDoneLoading 函数以订阅 xfbml.render 操作并在测试上设置超时:

window.fbAsyncInit = function () {
FB.init({ ... }); // 在你的 FB.init 代码之后

$(document).ready(function () {
    FB.Event.subscribe('xfbml.render',
  function () {
    setTimeout( function(){
        var str_timeline;
        var tlsrc = $("#timeline-hidden").find("iframe").first().css("height");

        if("0px"==tlsrc)
            str_timeline = '<strong><span style="color:red">This user DOES NOT have timeline.</span></strong>';
        else
            str_timeline = "<strong>This user DOES have timeline.</strong>";


        $("#timeline-test").html(str_timeline + ", timeline plugin css height:" + tlsrc);
    }, 250);
  }
);

});

};

我在测试中发现将 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:

<div id="timeline-hidden" style="display:none">
  <div class="fb-add-to-timeline" data-show-faces="true"></div>
</div>
<div id="timeline-test"></div>

Then, in your javascript (this use jQuery, FYI):

window.fbAsyncInit = function () {
FB.init({ ... }); // after your FB.init code

    FB.Canvas.setDoneLoading(
  function (result) {

    var str_timeline;
    var tlsrc = $("#timeline-hidden").find("iframe").first().css("height");

    if("0px"==tlsrc)
        str_timeline = '<h2 style="color:red">This user DOES NOT have timeline.<h2>';
    else
        str_timeline = "<h2>This user DOES have timeline.</h2>";

    $("#timeline-test").html(str_timeline + ", timeline plugin css height:" + tlsrc + ", loadtime: " + result.time_delta_ms);
  }
);

};

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

$(document).ready(function () {
    FB.Event.subscribe('xfbml.render',
  function () {
    setTimeout( function(){
        var str_timeline;
        var tlsrc = $("#timeline-hidden").find("iframe").first().css("height");

        if("0px"==tlsrc)
            str_timeline = '<strong><span style="color:red">This user DOES NOT have timeline.</span></strong>';
        else
            str_timeline = "<strong>This user DOES have timeline.</strong>";


        $("#timeline-test").html(str_timeline + ", timeline plugin css height:" + tlsrc);
    }, 250);
  }
);

});

};

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文