0
require_once 'library/facebook/facebook.php';

$facebook = new Facebook(array(
'appId'  => 'appid',
'secret' => 'secret',
));

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

以上代码后如何获取UID。

4

2 回答 2

1

您不需要为此包含 facebook api。就这一点,

$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
echo $data["user_id"];

这是$data数组中其他信息的完整列表。

{
  "algorithm": "HMAC-SHA256",
  "expires": 1317243600,
  "issued_at": 1317239909,
  "oauth_token": "<token>",
  "page": {
    "id": "<id>",
    "liked": false,
    "admin": true
  },
  "user": {
    "country": "in",
    "locale": "en_GB",
    "age": {
      "min": 21
    }
  },
  "user_id": "<user-id>"
}
于 2012-06-05T07:57:43.487 回答
0

由于您使用的是php sdk,

你可以简单地说

$user = $facebook->getUser();

PHP sdk 将从 signed_request 中读取 uid。

或者

您可以通过此直接从签名请求中获取

$signed_request = $facebook->getSignedRequest();
$user = isset($signed_request['user_id']) ? $signed_request['user_id'] : '';
于 2012-06-05T08:05:47.380 回答