无法获得Facebook Cookie并执行代码

时间:2011-12-15 16:10:21

标签: facebook-graph-api facebook

因为我是facebook图形API的新手,但我知道基础知识。现在我需要你们的帮助,如何阅读用户墙贴和其他任何用户墙上贴有read_stream的人。但我不知道如何打电话。我尝试了某种方式,但我能够阅读jus名称和基本信息。我需要帮助阅读对象。请帮帮我!!!

<?php header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND    
 CNT"');?>
<?php

define('FACEBOOK_APP_ID', 'xxxxx');
define('FACEBOOK_SECRET', 'xxxxxxxxx');

function get_facebook_cookie($app_id, $application_secret) {
$args = array();
print_r($_COOKIE);
parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
ksort($args);
$payload = '';
foreach ($args as $key => $value) {
    if ($key != 'sig') {
        $payload .= $key . '=' . $value;
    }
}
if (md5($payload . $application_secret) != $args['sig']) {
  return null;
}
return $args;
}

$cookie = get_facebook_cookie($app_id, $application_secret);
   echo 'The ID of the current user is ' . $cookie['uid'];

 ?>
 <html>
  <body>
  <?php if ($cookie) { ?>
  Your user ID is <?= $cookie['uid'] ?>
<?php } else { ?>
  <fb:login-button>Install Example App</fb:login-button>
<?php } ?>

<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
  FB.init({appId: 'xxxxxx', xfbml: true,cookie:true});
  FB.Event.subscribe('auth.login', function(response) {
    // Reload the application in the logged-in state
    window.top.location = 'http://apps.facebook.com/fbvantivirus';
  });
</script>
<div style="display:none">
  </body>
 </html>

我已经提到了整个代码。请帮助我。从上周开始挣扎。所有尝试都是徒劳。谢谢你提前。 :)

1 个答案:

答案 0 :(得分:0)

欢迎来到Cookie Hell。您需要P3P紧凑策略。 在iframe中,第一行:

<?php header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');?>