Thursday, 8 August 2013

How to integrate CakePHP-app to Facebook canvas

How to integrate CakePHP-app to Facebook canvas

I have problems integrating CakePHP-app (2.3.8) to Facebook canvas. When I
load the app-page in Facebook, the answer is:
The request has been black-holed
Error: The requested address '/?fb_source=search&ref=ts&fref=ts' was not
found on this server.
I have defined in Facebook's app settings that my Canvas secure URL is:
https://facebook.mydomain.com/
So the page is found by Facebook. (actually if the CakePHP's tmp/
directory is not writable, the Facebook's app-page displays the error
message about that -> so the URL is at least correct)
I have used Facebook PHP-SDK for integrating to Facebook. My page works as
a standalone page, but integrating to Facebook Canvas is the problem.
Here is my Config/facebook.php
$config = array(
'Facebook' => array(
'appId' => '***********',
'secret' => '**********************'
)
);
And here is my Controller for Facebook related stuff:
public function login() {
Configure::load('facebook');
$appId = Configure::read('Facebook.appId');
$app_secret = Configure::read('Facebook.secret');
$facebook = new Facebook(array(
'appId' => $appId,
'secret'=> $app_secret
));
$loginUrl = $facebook->getLoginUrl(array(
'scope' => 'user_birthday,user_location',
'redirect_uri' => BASE_URL .
'books/facebook_connect',
'display' => 'popup'
));
$this->redirect($loginUrl);
}
public function facebook_connect() {
Configure::load('facebook');
$appId = Configure::read('Facebook.appId');
$app_secret = Configure::read('Facebook.secret');
$facebook = new Facebook(array(
'appId' => $appId,
'secret'=> $app_secret
));
$user = $facebook->getUser();
// And the rest of this function is only for saving the authenticated user
to the database
All the tutorials I have found are pretty straightforward and they make it
look so easy to integrate to Facebook canvas. I have not succeeded even in
getting the most simple "hello world"-page with only index.php and
facebook php-sdk to work. I have tried also with cookies set to true, but
that didn't help either.
This is pretty broad question and it must be hard to imagine what could be
wrong in my case, but if you can find out anything or had suffered from
similar errors, please share your knowledge.

No comments:

Post a Comment