I verified that my appid,appsecret were correct and that my access_token is correct and valid. I am still receiving an "Error validating app." error message. Does anyone know why this might be?
<?php
define('YOUR_APP_ID', 'x');
define('YOUR_APP_SECRET', 'x');
function get_facebook_cookie($app_id, $app_secret) {
$args = array();
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 . $app_secret) != $args['sig']) 开发者_运维问答{
return null;
}
return $args;
}
$cookie = get_facebook_cookie(YOUR_APP_ID, YOUR_APP_SECRET);
$access_token="AAADDMjYCsTABAAbzGa3vLtSq7rt4iZBmnuFXUDRVxVnZAm8HbQp2chBBUIfJpAADiJWOu5TIPr0tnnKDhLEbXCicqLl8sP6KFT1vb8ZCkz6PeuUMUIs";
$url = 'https://graph.facebook.com/me?access_token=' . $access_token;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
curl_close($ch);
$user = json_decode($response);
print_r($user);
?>
<html>
<body>
<?php if ($cookie) { ?>
Welcome <?php ?>
<?php } else { ?>
<fb:login-button></fb:login-button>
<?php } ?>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({appId: '<?= YOUR_APP_ID ?>', status: true,
cookie: true, xfbml: true});
FB.Event.subscribe('auth.login', function(response) {
window.location.reload();
});
</script>
</body>
</html>
I'd recommend you to keep you appid and appsecret secret. Do not post it in websites like this.
精彩评论