如何使用 facebook 注册插件获取在我的网站上注册的 facebook 用户的用户 ID。
Graph Api 表示每个 facebook 对象都有一个唯一的 ID。
我想知道一种获取此 ID 的方法。
注册插件的json代码为:
<iframe src='http://www.facebook.com/plugins/registration.php?
client_id=325340244194060&
redirect_uri=http://www.pingcampus.com/facebook_registration_plugin/store_user_data.php&
fields=[
{
"name": "name"
},
{
"name": "email"
},
{
"name": "gender"
},
{
"name": "birthday"
},
{
"name": "captcha"
}
]'
scrolling="auto"
frameborder="no"
style="border:none"
allowTransparency="true"
width="500"
height="800"
>
</iframe>
我用来获取详细信息的 PHP 代码是:
<?php ob_start();
define('FACEBOOK_APP_ID', '325340244194060');
define('FACEBOOK_SECRET', '2ab5cb734f39d8417569cc7be7a0e89a');
// No need to change function body
function parse_signed_request($signed_request, $secret) {
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
// decode the data
$sig = base64_url_decode($encoded_sig);
$data = json_decode(base64_url_decode($payload), true);
if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
error_log('Unknown algorithm. Expected HMAC-SHA256');
return null;
}
// check sig
$expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
if ($sig !== $expected_sig) {
error_log('Bad Signed JSON signature!');
return null;
}
return $data;
}
function base64_url_decode($input) {
return base64_decode(strtr($input, '-_', '+/'));
}
if ($_REQUEST) {
$response = parse_signed_request($_REQUEST['signed_request'],
FACEBOOK_SECRET);
/*
"<pre>";
print_r($response);
"</pre>"; // Uncomment this for printing the response Array
*/
$name = htmlentities($response["registration"]["name"]);
$email = htmlentities($response["registration"]["email"]);
$gender = htmlentities($response["registration"]["gender"]);
$dob = htmlentities($response["registration"]["birthday"]);
$phone = htmlentities($response["registration"]["phone"]);
} else {
echo '$_REQUEST is empty';
}
?>