I am attempting a test app to learn on facebook. I am using this code from the facebook developer page:
<?php
$app_id = "YOUR_APP_ID";
$canvas_page = "YOUR_CANVAS_PAGE_URL";
$auth_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($canvas_page);
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (empty($data["user_id"])) {
echo("<script> top.location.href='" . $auth_url . "'</script>");
} else {
echo ("Welcome User: " . $data["user_id"]);
}
?>
When I run this I get:
Message: Undefined index: signed_request
I am using this in Codeigniter. I have no idea if that matters.. When I run this it uses the $auth_url and return:
http://mydomain.com/responsepage?code=biglongstring
so I know I am getting to facebook and getting something...
In that string url returned is a variable named "code." I tried to change the $_REQUEST object to look for "code" but it gives the same error.
It does redirect me back to my response page after it briefly displays the error because the "user_id" element is empty. It is empty because signed_request is not present in the url sent back.
What am I doing wrong? It should go to facebook, ask for me to allow the app, display the user_id. For some reason the signed_request just isn't there.
Thank you.
EDIT: I'm looking at this again. Where does it ever actually go out and use that URL?
EDIT: If I use the $auth_url manually, pasting it in the address of the browser it redirects back to my response page with no problem. Of course, I did not see a variable named signed_request, just "code" so I don't know what's going on.