单击“喜欢”时如何阻止粉丝门/喜欢门重定向到墙

发布于 2024-12-05 12:52:23 字数 757 浏览 1 评论 0原文

我创建了一个 Facebook 粉丝页面,用作粉丝门/类似门。当用户单击“喜欢”按钮时,页面会重定向到墙。我想覆盖此行为并将页面重定向回粉丝门的“喜欢”版本。该应用程序是一个 iFrame 页面选项卡应用程序,使用 PHP 签名请求来确定喜欢/不喜欢的状态。

例如 http://www.facebook.com/1800flowers 当您喜欢该页面时,它会将您重定向到 http://www.facebook.com/1800flowers?sk =app_116748578401618

所以我的搜索找到了一段应该可以解决这个问题的JavaScript:

<script type="text/javascript">
    if (top != self) top.window.location = 'linkgoeshere';
</script>

我尝试放置该 JavaScript 块位于页面的“喜欢”和“不喜欢”部分。无论哪种方式,它都会创建一个重定向循环,页面不断刷新。

如果此代码是答案,那么它应该位于哪里,以及“linkgoeshere”应该替换为什么?我可能使用了错误的链接。

如果这不是答案,还有其他选择吗?

I've created a Facebook fan page that works as a fan gate / like gate. When the user clicks the "Like" button the page redirects to the wall. I want to override this behavior and have the page redirect back to the Liked version of the fan gate. The app is an iFrame page tab app using the PHP signed request to determine liked/notliked status.

An example of this is http://www.facebook.com/1800flowers
When you like the page, it redirects you to http://www.facebook.com/1800flowers?sk=app_116748578401618

So my search-fu found a piece of JavaScript that was supposed to fix this:

<script type="text/javascript">
    if (top != self) top.window.location = 'linkgoeshere';
</script>

I've tried placing this block of JavaScript in both the have liked and have not liked sections of the page. Either way it creates a redirect loop where the page just continually refreshes.

If this code is the answer, where should it be located, and what should "linkgoeshere" be replaced with? There is a possibility I've been using the wrong link.

If this isn't the answer, is there an alternative?

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

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

发布评论

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

评论(4

心凉 2024-12-12 12:52:23

这是目前 Facebook 上的一个错误,描述如下 - https://developers.facebook.com/bugs/110015112440103

如果能有一个临时修复就太好了,但由于“Like”按钮的代码不在页面选项卡可访问的范围内,所以我无法想象解决方案可能是什么样子,无法从页面中删除地址以使其不再是“位置”,而“位置”似乎是唯一受影响的页面。

This is a bug on facebook right now, described here - https://developers.facebook.com/bugs/110015112440103

It'd be great to have an interim fix but since the code for the Like button is outside of what's accessible to the page tab, I'm having trouble imaging what a solution might look like, short of removing the address from your page to make it not a "place", which seem to be the only pages affected.

春风十里 2024-12-12 12:52:23

这几天我一直遇到这个问题,但今天我找到了解决方案。您的怀疑是正确的,这是由页面上新的推荐对话框引起的。此框仅出现在“地点”页面上。如果您的页面分配了地址,请将其删除,您的 fangate 将在点赞时重新加载到窗口中,而不是重定向到墙页。

I've been having this problem for the past few days, but today I found the solution. You were right with your suspicions that this is caused by the new recommend dialog box on pages. This box only appears on pages for PLACES. If you have a address assigned to your page then remove it and your fangate will reload in the window when liked and not redirect to the wallpage.

夜深人未静 2024-12-12 12:52:23

你不应该需要任何 JavaScript。

确保您在管理页面的“管理权限”部分将“默认登陆选项卡”设置为您的扇门。

You shouldn't need any JavaScript.

Makes sure you set the "Default Landing Tab" to be your fan gate in the "Manage Permissions" section of the page Admin.

咿呀咿呀哟 2024-12-12 12:52:23

这是我使用的解决方案。另外,请确保按照上面标记设置默认登陆选项卡。您需要下载适用于 php 的最新 facebook sdk,并将您的应用程序 ID、应用程序密钥和粉丝专页路径替换为下面的 $loginNextPage。

请注意,您可以在两个位置添加自己的 HTML 或包含应为适当受众提供的页面内容。

此外,无论您将什么设置为默认选项卡,喜欢您页面的回访用户总是会默认看到墙。因此,如果他们离开并回来,他们就会得到隔离墙。

 <?php

    require 'facebook.php';                

    $app_id = "YOUR APP ID";
    $app_secret = "YOUR APP SECRET";
    $loginNextPage = 'YOUR FAN PAGE URL'.'?sk=app_'.$app_id;

    $facebook = new Facebook(array(
            'appId' => $app_id,
            'secret' => $app_secret,
            'cookie' => true
    ));



    $signed_request = $facebook->getSignedRequest();

    $page_id = $signed_request["page"]["id"];
    $like_status = $signed_request["page"]["liked"];


    if ($like_status) {
        // FOR FANS
        $session = $facebook->getSession();
        $loginUrl = $facebook->getLoginUrl(
                array(
                'canvas'    => 1,
                'fbconnect' => 0,
                'next' => $loginNextPage,
                'req_perms' => 'publish_stream,photo_upload,user_photos,user_photo_video_tags'          
                )
        );

        $fbme = null;

        if (!$session) {
            echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";    
            exit;   
        }
        else {

            try {
                $access_token = $facebook->getAccessToken();
                $fbme = $facebook->api('/me');
                $user = $facebook->getUser();

                $url = "https://graph.facebook.com/".$user;
                $info = file_get_contents($url);
                $info = json_decode($info); 
                $vars = "id=$user&first_name=$info->first_name&last_name=$info->last_name&access_token=$access_token&pathToServer=$pathToServer&appName=$appName";

            } catch (FacebookApiException $e) {
                echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
                exit;
            }


    // Begin Like Gated Content.        
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">   
    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
    <head>
    </head>
    <body>
    <h1>You Have Liked The Page</h1>
        </body>
    </html>
    <?
        }   
    }
    else {
        // FOR NON FANS
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">   
    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
    <head>
      </head>
      <body>
      <h1>Click Like To View Content</h1>
        </body>
    </html>
    <?
    }
    ?>

Here is the solution I use. Also, be sure as marked above to set the default landing tab. You will need to download the latest facebook sdk for php, and replace the lines for your app ID, app secret, and the path to your fanpage int he $loginNextPage below.

Notice that there are two places where you can add your own HTML or an include of the page content that should be served for the appropriate audiences.

Also, returning users who liked you pages always get the wall by default, no matter what you set as the default tab. So if they leave and come back, they will get the wall.

 <?php

    require 'facebook.php';                

    $app_id = "YOUR APP ID";
    $app_secret = "YOUR APP SECRET";
    $loginNextPage = 'YOUR FAN PAGE URL'.'?sk=app_'.$app_id;

    $facebook = new Facebook(array(
            'appId' => $app_id,
            'secret' => $app_secret,
            'cookie' => true
    ));



    $signed_request = $facebook->getSignedRequest();

    $page_id = $signed_request["page"]["id"];
    $like_status = $signed_request["page"]["liked"];


    if ($like_status) {
        // FOR FANS
        $session = $facebook->getSession();
        $loginUrl = $facebook->getLoginUrl(
                array(
                'canvas'    => 1,
                'fbconnect' => 0,
                'next' => $loginNextPage,
                'req_perms' => 'publish_stream,photo_upload,user_photos,user_photo_video_tags'          
                )
        );

        $fbme = null;

        if (!$session) {
            echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";    
            exit;   
        }
        else {

            try {
                $access_token = $facebook->getAccessToken();
                $fbme = $facebook->api('/me');
                $user = $facebook->getUser();

                $url = "https://graph.facebook.com/".$user;
                $info = file_get_contents($url);
                $info = json_decode($info); 
                $vars = "id=$user&first_name=$info->first_name&last_name=$info->last_name&access_token=$access_token&pathToServer=$pathToServer&appName=$appName";

            } catch (FacebookApiException $e) {
                echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
                exit;
            }


    // Begin Like Gated Content.        
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">   
    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
    <head>
    </head>
    <body>
    <h1>You Have Liked The Page</h1>
        </body>
    </html>
    <?
        }   
    }
    else {
        // FOR NON FANS
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">   
    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
    <head>
      </head>
      <body>
      <h1>Click Like To View Content</h1>
        </body>
    </html>
    <?
    }
    ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文