How to access the values of the custom fields filled in at facebook registration form?
I was wondering how to access the custom fields people filled in after registering on your site with Facebook registration form.
I understand the usage of the PHP SDK environment a bit, and can access gender, name, etc. easily, but I have no idea how to do this with开发者_开发知识库 custom fields you yourself created.
I would prefer to receive an answer related to PHP SDK, but any is good.
thanks in advance!
Once the registration form is submitted, a signed_request
holding ALL the data you need will be send back to your server on the URL you specify redirect_uri
, how to "extract" these data is explained in the documentation (PHP Example reading signed_request
section):
<?php
define('FACEBOOK_APP_ID', 'your_app_id');
define('FACEBOOK_SECRET', 'your_app_secret');
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) {
echo '<p>signed_request contents:</p>';
$response = parse_signed_request($_REQUEST['signed_request'],
FACEBOOK_SECRET);
echo '<pre>';
print_r($response);
echo '</pre>';
} else {
echo '$_REQUEST is empty';
}
?>
精彩评论