Topic-icon Own Facebook apps using JFBC libraries

Active Subscriptions:

None
11 years 2 months ago #31057 by playak
I'm using the JFBC libraries in a couple of my own components to make API calls, FQL queries etc. Works great.

However I want to take it one step further and even use the same libraries for a couple of Facebook apps that have a completely different appid and secret. Right now I'm getting the 'Bad Signed JSON signature' errors on those pages, and I assume that's because of the wrong appid. Any ideas on how I can make those apps use the correct appids and secrets? JFBConnectFacebookLibrary::getInstance(); doesn't take any parameters...

Thanks for ideas,
Jeroen
The topic has been locked.
Support Specialist
11 years 2 months ago #31087 by alzander
Jeroen,
We haven't really dealt with that before, but I have something that may work for you. You can easily set the app id and app secret using JFBConnect, it's important to make sure you reset it back to the JFBConnect keys when you're done. That way, if JFBConnect needs to make any calls later, they won't fail (or go to the wrong app).

So, code like below should work for you as a wrapper for you:
$jfbcLibrary = JFBConnectFacebookLibrary::getInstance();
$fbClient = $jfbcLibrary->getFbClient();
$jfbcAppId = $fbClient->getAppId();
$jfbcSecretKey = $fbClient->getAppSecret();

$fbClient->setAppId('12345');
$fbClient->setSecretKey('xyz');

// ADD YOUR CODE HERE. Can use $jfbcLibrary->api(...) as normal

$fbClient->setAppId($jfbcAppId);
$fbClient->setSecretKey($jfbcAppSecret);
The other think that you'd likely need/want to do is in the /components/com_jfbconnect/libraries/facebook.php file, edit the api and rest functions. In both, you'll see:
$params['access_token'] = $this->facebookAppId . "|" . $this->facebookSecretKey;
Change those to:
$params['access_token'] = $fbClient->getAppId() . "|" . $fbClient->getAppSecret();
That will make sure the 'current' app and secret keys are used in those calls.

Whew, hope that helps get you going. Should you run into issues or have other questions though, just let us know.

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
11 years 2 months ago #31097 by playak
Glad I asked :) Thanks for the super feedback.

I use this on Facebook-framed app pages, so I'm not sure if I should give this back to the JFBC app after doing my app things, like you proposed. Or is this required to keep things working for other browser windows in the same session?
The topic has been locked.
Support Specialist
11 years 2 months ago #31105 by alzander
It's up to you to 'reset' the app ID/Key. It really matters when you're doing your functionality. Right as Joomla is starting up to create a page, JFBConnect can do some communication with Facebook if the user just logged in or something like that. After the page starts rendering though, there likely isn't any more communication with Facebook. So, if you're doing your code 'early' in the process, it's safest to reset the keys to make sure JFBConnect doesn't get the same errors you were. If it's later (like when a component layout is being rendered) you'd be less likely to run into issues by just leaving the keys.

Hope that makes sense,
Alex
The topic has been locked.