0

所以基本上我试图让一个类似的门工作,但 $like_status 变量永远不会改变,所以我改变为喜欢的内容的条件永远不会起作用。有谁知道为什么这永远不会改变?已将我的应用程序添加到 facebook 上的页面选项卡,它获取所有其他变量 $page_id、$page_admin、$country 和 $locale,但没有 $like_status。

谢谢查理

请参阅下面的代码

<?php

    enter code here

require_once('AppInfo.php');

// Enforce https on production
if (substr(AppInfo::getUrl(), 0, 8) != 'https://' && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
  header('Location: https://'. $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
  exit();
}

// This provides access to helper functions defined in 'utils.php'
require_once('utils.php');


require 'includes/facebook.php';


// Create our Application instance.
$facebook = new Facebook(array(
  'appId'  => AppInfo::appID(),
  'secret' => AppInfo::appSecret(),
  '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"];

echo "<br>page id = $page_id";
echo "<br>page admin = $page_admin";
echo "<br>like status = $like_status";
echo "<br>country = $country";
echo "<br>locale = $locale";

function grokSignedRequest() 
{
    if (isset($_REQUEST['signed_request'])) 
    {
      $encoded_sig = null;
      $payload = null;
      list($encoded_sig, $payload) = explode('.', $_REQUEST['signed_request'], 2);
      $sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
      $data = json_decode(base64_decode(strtr($payload, '-_', '+/'), true));
      return $data;
    }
    return false;
}



// call the function to parse the signed request
$sr_data = grokSignedRequest();



// check like status
if ($sr_data->page->liked==1) 
{
    include ('includes/index2.php');
} 

else
{
  include ('includes/index1.php');
}

?>
4

2 回答 2

1

如果您在标签页上运行您的 PHP 代码,like_status则可能实际存在,但设置为值 0(零)。因此,该echo语句似乎没有为 输出任何内容$like_status,但实际上它的值为零。为了证明这一点,试试这样的代码:

if ($like_status == 0)
    echo "it's zero";
else 
    echo "it's not zero";
于 2012-07-18T01:36:26.910 回答
0

编辑:对不起,我没有看到@robbie 在问题的评论中解决了这个问题

用户必须从页面选项卡到达应用程序,并且:

与 Canvas 页面一样,在用户授权您的应用之前,您不会在 signed_request 中收到您的应用可访问的所有用户信息。

https://developers.facebook.com/docs/appsonfacebook/pagetabs/#integrating

于 2014-05-26T12:06:30.310 回答