Search code examples
facebook-php-sdkaccess-tokenfacebook-canvas

Correct way to link to new page in canvas page app php-sdk


I'm running in to a couple of issues and wondered if anyone had any insight. I'm using the latest php-sdk I'm developing a canvas app that has a number of different steps. These steps are spread across multiple pages. Now when I first enter the app everything seems to work fine. The access token is there and I can call the api functions. On the second page (which is linked to in the same iframe) I get OAuth errors. Now if I use this on the 2nd page:

 $me = $facebook->getUser();
 var_dump($me);

it returns the correct user id, but I still get errors when trying to use an api query (specifically a FQL one in this instance)

Now, bear in mind these links are within the iframe so I was assuming the signed_request is getting lost somewhere, I know facebook normally issues this via a POST. If I set all my links to target="_parent" with a url such as http://apps.facebook.com/myapp/page2.php then everything works fine. Facebook clearly posts the correct info this time. Subsequently, then when I use links that only redirect the iframe it seems to work fine again (implying a cookie is being set somewhere).

Now I've seen other apps that don't have a target="_parent" that seem to work correctly, only ever loading the iframe on subsequent clicks and not the full facebook site. So I can only assume they are storing this info somewhere. I've tried to inspect these apps using httpfox but I can't see anything obvious. Does anyone have any links for best practice with multiple page apps? I know I can get around this using full urls and target="_blank" but I would like to know what's going on here. I've looked through the developer docs and the canvas page examples, but there's nothing obvious to me.

Any help or info would be appreciated

Many Thanks


Solution

  • There is some ways to achieve this

    • using Facebook JavaScript SDK (which will set cookie for you, so PHP-SDK can rely on it)
    • issuing POST request to your pages including signed_request from initial page loaded in canvas