简体   繁体   English

facebook $facebook->getSignedRequest(); 错误

[英]facebook $facebook->getSignedRequest(); error

i am trying to add this script to my iframe app on facebook but it seems not to work:我正在尝试将此脚本添加到 facebook 上的 iframe 应用程序中,但它似乎不起作用:

    $signed_request = $facebook->getSignedRequest();
$like_status = $signed_request["page"]["liked"];
// If a fan is on your page
if ($like_status) {
echo 123;
} else {
// If a non-fan is on your page
echo 456;
}

i am placing the right app id and secret key and im calling facebook.php the right way.我正在放置正确的应用程序 ID 和密钥,并以正确的方式调用 facebook.php。 I get no errors or warnings, just that the script doesn't work.我没有收到任何错误或警告,只是脚本不起作用。

$like_status doesn't return anything $like_status不返回任何内容

did the script changed?剧本改变了吗? is there another version?还有其他版本吗? thanks谢谢

edit.编辑。 more code:更多代码:

<?php
require 'facebook.php';
$app_id = "11549508592";
$app_secret = "d898cb58b16f2aaaaaaaaaaaaaa";
$facebook = new Facebook(array(
    'appId' => $app_id,
    'secret' => $app_secret,
    'cookie' => true
));
$signed_request = $facebook->getSignedRequest();
$like_status = $signed_request["page"]["liked"];
echo "<br>like status = $like_status";
?>

I had similar problem a while ago - the solution was to specify full url for tab or/and canvas page to receive signed request.不久前我遇到了类似的问题 - 解决方案是为选项卡或/和 canvas 页面指定完整的 url 以接收签名请求。

Example: use http://myapp.com/myapp/index.php , isntead of http://myapp.com/myapp/示例:使用http://myapp.com/myapp/index.php代替http://myapp.com/myapp/

Facebook sends the signed request to your page when it is called from facebook.当从 facebook 调用时,Facebook 将签名请求发送到您的页面。

So:所以:

$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);

$_REQUEST['signed_request'] could be empty if your canvas (or page tab) URL is not the final one and redirects to some other URL because Facebook posts the signed request only once. $_REQUEST['signed_request'] could be empty if your canvas (or page tab) URL is not the final one and redirects to some other URL because Facebook posts the signed request only once. When redirecting, the posted value is lost.重定向时,发布的值会丢失。

If you have some control over the redirection, then add ?signed_request=$_REQUEST['signed_request'] to your redirected URL (you might also need to pass other custom GET parameters)如果您对重定向有一些控制,则将?signed_request=$_REQUEST['signed_request']添加到重定向的 URL (您可能还需要传递其他自定义 GET 参数)

Unfortunately, I had the same issue.不幸的是,我遇到了同样的问题。 After hours and hours trying to solve it, I finally created a new application, with exactly the same set up.经过几个小时的尝试解决它,我终于创建了一个新的应用程序,设置完全相同。 I updated key and secret in my code to the new ones and voilà - its running like a charm from the first attempt.我将代码中的密钥和秘密更新为新的,——从第一次尝试开始,它就像魅力一样运行。

Definitly a Facebook issue.绝对是 Facebook 问题。 Maybe resetting App ID and secret could also had worked, but I didn't try that first.也许重置 App ID 和密码也可以,但我没有先尝试。

  • what is the version of facebook php sdk? facebook php sdk 的版本是什么?
  • check access_log and error_log in your web server检查 web 服务器中的 access_log 和 error_log
  • have you some missing ";"?你有没有遗漏“;”?

Not sure whats wrong here, but here is a basic page that it will work on.不知道这里出了什么问题,但这是一个可以处理的基本页面。 Make sure that the latest version of facebook.php and base_facebook.php is in the same directory.确保最新版本的 facebook.php 和 base_facebook.php 在同一目录下。 You can find the sdk here: https://github.com/facebook/php-sdk Allso remember to put in your app id and secret where you se all the 111111111111111's您可以在此处找到 sdk: https://github.com/facebook/php-sdk请记住在您看到所有 111111111111111 的位置输入您的应用程序 ID 和密码

<?php 

require 'facebook.php';

$app_id ="11111111111111111";
$app_secret = "11111111111111111111111111";

$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"];



?>

<!DOCTYPE html>  
<html lang="en">  
    <head>
    <meta charset="utf-8"/>
    <title>untiteled</title>


    <script type="text/javascript">
        window.fbAsyncInit = function() {
            FB.Canvas.setSize(); 
        }

    </script>


</head>
<body>
    <div class="wrapper">

        <?php if(!$like_status):?> 
            <div class="likearrow"><div><div></div></div></div>
            <p id="like">Click "<b>like</b>" if you want to become a fan of this app</p>
        <?php endif; ?>

        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

    </div>

<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
    appId: '111111111111111111111',
    status: true,
    cookie: true,
    xfbml: true

});
</script>       
</body>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM