2

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.

johnny
  • 19,272
  • 52
  • 157
  • 259

2 Answers2

2

Okay it seems that you are using your Canvas URL in the $canvas_page variable which is wrong. You need to use the Canvas Page which is something like: http://apps.facebook.com/appnamespace

This way, your app will open inside the iframe and Facebook will be able to send you the signed_request

ifaour
  • 38,035
  • 12
  • 72
  • 79
  • oh crap I'm dumb. I was going to my webpage instead of apps.facebook.com/my_app. thanks. – johnny Sep 23 '11 at 20:40
  • why would I get API Error Description: The specified URL is not owned by the application? I put in http://apps.facebook.com/mynamespace for the $canvas_page variable. – johnny Sep 23 '11 at 22:14
0

Make sure that you have "signed_request for Canvas" enabled in settings->advanced->migrations Then you should get the signed_request via $_POST.

dtrejogo
  • 241
  • 1
  • 6
  • 18