0

我查看了浏览器中的源代码 facebbok 在代码中创建了一个表单,这

<form method="post" id="proxy_form"> <input type="hidden" autocomplete="off" id="signed_request" name="signed_request" /> </ form> <script> document.domain = "facebook . to ";
   FrameName window.location.href.split var = ('#') [1];
   submitForm function (appTabUrl, signedRequest) {
     var proxyForm = document.getElementById ("proxy_form");
     proxyForm.setAttribute ("action", appTabUrl);
     proxyForm.setAttribute ("target", FrameName);
     var input = document.getElementById ("signed_request");
     input.setAttribute ("value", signedRequest);
     proxyForm.submit ();
   }
   waitForParams function () {
     if (parent.PlatformAppController &&
           parent.PlatformAppController.getFrameParams (FrameName) &&
         document.getElementById ("proxy_form") &&
         document.getElementById ("signed_request")) {
       var params =
         parent.PlatformAppController.getFrameParams (FrameName);
       submitForm (params.appTabUrl, params.signedRequest);
     Else {}
       setTimeout (waitForParams, 10);
     }
   }
   waitForParams (); </ script> <div <noscript> class="pam uiBoxGray"> You need to enable Javascript in your browser to use Facebook Applications. </ div> </ noscript>

  我的 javascript 已启用,我测试了 3 台不同的机器

4

1 回答 1

1

我有这段代码,但它在 Chrome 中也不起作用(仅适用于粉丝)。对于非粉丝,它正确显示了图像。

我刚刚将重定向更改为HTTPS,它已经奏效了!:) 看起来 Chrome 在重定向到 http 方面存在问题。只需在所有链接中添加一个“s”,它应该可以工作。

请注意隐藏的重定向,如果您有参数 URL 或类似的东西,则需要在其中添加两次“s”:在开头 ( https://www.myweb.com/r.php?) 和中间 ( &url=https%3A//www.myweb.es)

希望能帮助到你!

一个例子:

<?php

require 'facebook.php';

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

$signed_request = $facebook->getSignedRequest();

$page_id = $signed_request["page"]["id"];
$page_admin = $signed_request["page"]["admin"];
$like_status = $signed_request["page"]["liked"];
$country = $signed_request["user"]["country"];
$locale = $signed_request["user"]["locale"];

if ($like_status) {

    if ($page_id == '1234567890'){
    // UK
        header("HTTP/1.1 301 Moved Permanently");
        header("Location: https://www.myweb.com/fbpromo/");
        exit();
    } 
}
else {
    echo "<link type='text/css' rel='stylesheet' href='facebook_new.css'/>";
    echo "<body>";
    if ($page_id == '1234567890'){
        //English
        echo "<img src='http://www.myweb.com/img/facebook/FB-app-non-fans.jpg' alt='Like us' /> ";
    }
}

echo "</body>";

?>
于 2013-11-04T14:04:48.240 回答