1

I am using the latest versions of both JavaScript(2.0) and PHP(4.0) Facebook SDKs, together. My app id and secrect are set up for both. I am also developing locally, if that might be the issue.

MY Javascript SDK succesfully retrieves a users profile from FB. It also succesfully creates a cookie. The user profile information IS inside the cookie, I can access the cookie from JS but now I need to use PHP with the information.

https://developers.facebook.com/docs/php/FacebookJavaScriptLoginHelper/4.0.0 Facebook says you can access your JS SDK information from PHP using FacebookJavaScriptLoginHelper.

$helper = new FacebookJavaScriptLoginHelper();
$session = $helper->getSession();

This returns null. I have also set up my PHP SDK following: https://developers.facebook.com/docs/php/gettingstarted/4.0.0

My code doesn't seem to show any errors at all, and all my PHP FB Objects are valid. There is only a couple solutions to this issue on the internet, and this one is the closest: Facebook Login: How to combine JavaScript with PHP SDK?

But the code is depreciated and does not work at all. Facebook class doesn't exist in the new versions of the SDK's and I was wondering if anyone knows how to access the SDK data from PHP?

Community
  • 1
  • 1
user3753569
  • 1,775
  • 5
  • 14
  • 18
  • inspect the contents of the $_SESSION superglobal.. does a value exist for a key starting with fbsr_ ? Did you initialize the SDK with your App ID? – Fosco Jul 08 '14 at 17:51
  • I'm not too sure how to do that i'm fairly new to PHP. I tried print_r($_session) and it returned Array( ). I checked my cookies and yes, a value does exist for fbsr_###. I am using two different SDK's, so i have initialized both SDK's with their corresponding app id & secret. – user3753569 Jul 08 '14 at 18:02
  • Yeah, sorry, I meant $_COOKIE. Are you using: FacebookSession::setDefaultApplication('YOUR_APP_ID', 'YOUR_APP_SECRET'); where YOUR_APP_ID is the value after fbsr_ in the cookie?.. – Fosco Jul 08 '14 at 18:05
  • I used print_r($_COOKIE) and yes it shows my fbsr_APPID# cookie. Yes I have have initialized both sdks with: FacebookSession::setDefaultApplication('YOUR_APP_ID', 'YOUR_APP_SECRET'); – user3753569 Jul 08 '14 at 18:12
  • I'd suggest adding some logging inside the javascript login helper.. try troubleshooting to see where things are going wrong. – Fosco Jul 08 '14 at 18:17
  • Also, how are you installing the php sdk, through composer? what does your require line look like? should be using version 4.0.x – Fosco Jul 08 '14 at 18:18
  • No, i'm not using composer. I Downloaded the SDK , put the FaceBook folder @ the root. I used: require_once('Facebook/FacebookJavaScriptLoginHelper.php'); Then: use Facebook\FacebookJavaScriptLoginHelper; for each of the PHP files inside of: Entites,HttpClients and @ the root of the folder. – user3753569 Jul 08 '14 at 18:29

1 Answers1

1

I was using two different SDKs with two different AppIDs & secrets. The SDK's cannot be aware of each other this way unless you specify. so I simply used my Javascript SDK appID & secret values for my PHP SDK and they both work together now.

user3753569
  • 1,775
  • 5
  • 14
  • 18