So I'm re-writing our old Facebook app (from 2011), bring it up to snuff. It's a straight Canvas app - I just want it to run in the iFrame, it doesn't need any special permissions. I am trying to work from the sample in the PHP SDK docs, and I get no FacebookSession. Here's what I'm working with:
// initialize the FacebookSession with our app and secret
FacebookSession::setDefaultApplication($this->fbapp_settings['appId'], $this->fbapp_settings['secret']);
// create a canvas login helper to deal with login stuff
$this->loginHelper = new FacebookCanvasLoginHelper($this->fbapp_settings['appId'], $this->fbapp_settings['secret']);
try
{
$this->facebookSession = $this->loginHelper->getSession();
if (empty($this->facebookSession) )
{
throw new Exception("Error, no facebook session created");
}
// this is where my code will do something cool
}
catch (FacebookRequestException $ex)
{
throw new Exception("FacebookException: " . $ex->getMessage() );
}
catch ( Exception $ex)
{
throw new Exception("Elite Exception: " . $ex->getMessage() );
}
I tried with with "Client OAuth Login" both on and off. Looking in the code for FacebookCanvasLoginHelper->getSession, the problem is that the signedRequest that I get has no OAuthData. Weirdly, it seemed to be working fine early yesterday.
Any thoughts?
Thanks, Andy
Addendum: Per the previous comment, I re-added the login dialog. So my flow is: a) Facebook calls my app with a signed_request, which I use to create a FacebookSession, which doesn't have OAuth credentials, so I invoke the Login dialog (created via the FacebookRedirectLoginHelper->getLoginUrl function). The login dialog comes up. I press ok, and Facebook invokes my app again, with a code this time instead of a signed_request. I try to create a FacebookSession - first I need an AccesToken, so I invoke AccessToken::getAccessTokenFromCode, which throws an exception:
'Facebook\FacebookAuthorizationException' with message 'Error validating verification code. Please make sure your redirect_uri is identical to the one you used in the OAuth dialog request'
Once my app is given permission (through the login dialog) by the user, if I want to get the UID, is this the correct way to do it (i.e., using the "code" to create an AccessToken and use that to create a FacebookSession)? There is no place in the flow that I can see where i can input the redirect_uri - GetAccessTokenFromCode explicitly sets it to an empty string, I'm guessing that is the problem here.
thanks for your help, andy
$helper = new FacebookRedirectLoginHelper($redirect_url); $session = $helper->getSessionFromRedirect();- Nithya Sivakumar