Facebook Error: An error has occurred with the application. Please try again later
My code that was working until yesterday suddenly started throwing errors. I don't know what changed everything. It is also based on code from Facebook Parties Authentication . Also I have mentioned other posts with a similar title, but tried what they mention and no luck.
Here is the code
<?php
$app_id = "my app id";
$app_secret = "my app secret";
$my_url = "http://apps.facebook.com/myappnamespace";
// Tried https in my_url // Also tried to use direct app path with both http and https and doesn't work. session_start (); $ code = $ _REQUEST ["code"];
if(empty($code)) {
$_SESSION['state'] = md5(uniqid(rand(), TRUE)); //CSRF protection
$dialog_url = "https://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($my_url) . "&state="
. $_SESSION['state'];
echo("<script> top.location.href='" . $dialog_url . "'</script>");
}
if($_REQUEST['state'] == $_SESSION['state']) {
$token_url = "https://graph.facebook.com/oauth/access_token?"
. "client_id=" . $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret . "&code=" . $code;
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$graph_url = "https://graph.facebook.com/me?access_token="
. $params['access_token'];
$user = json_decode(file_get_contents($graph_url));
echo("Hello " . $user->name);
}
else {
echo("The state does not match. You may be a victim of CSRF.");
}
?>
There might be other ways to fix this, but the php path usually never worked for me. I changed my approach to Javascript sdk and everything was better.
You seem to be using HTTP in the redirect url, but you are trying to authenticate with HTTPS. Change the url in $my_url
to https://
and see if it works.