我环顾四周,所以如果这是一个重新发布的帖子,请向我发送正确的方向,但是当我运行这个时,我会不断获得一个随机字符。我究竟做错了什么?我只想输出用户ID。
<?php require 'facebook.php';
$facebook = new Facebook( array(
'appId' => "XXXXXXXXXXXXXXXXXXX",
'secret' => "XXXXXXXXXXXXXXXXXXXXXXX",
'cookie' => true
) );
try {
$me = $facebook->api('/me');
} catch ( FacebookApiException $e ) {
error_log( $e );
}
$signed_request = $_REQUEST["signed_request"];
$user_id = $signed_request['user_id'];
echo $user_id;
$signed_request = $facebook->getSignedRequest();
$liked = $signed_request['page']['liked'];
?>
$ signed_request ['page'] ['likes']也可以。
答案 0 :(得分:1)
这是您代码中的复制/粘贴吗? 如果是的话
$signed_request = $_REQUEST["signed_request"];
$user_id = $signed_request['user_id'];
echo $user_id;
不起作用,它不是正确的signed_request,因为你没有解密响应而无法读取(在PHP SDK中解密是'getSignedRequest()'函数中自动的)
您拥有的页面代码是正确的,因此要获取当前用户ID,假设用户已接受您应用的auth对话框,则代码应为
$signed_request = $facebook->getSignedRequest();
$user_id = $signed_request['user_id'];
echo $user_id