× Joomla Facebook Connect support forum

Topic-icon Auto Connect when inside canvas

Support Specialist
14 years 9 months ago #13217 by alzander
Ivan,
Sorry for the delay. We were slammed the last 2 days finalizing the 4.0 release, which was just posted. This release updates JFBConnect to use the new OAuth2 authentication mechanism that Facebook says they're require in October. Below, I'm giving two snippets of code that will check if the user is logged into Facebook before calling the jfbc.login.login_custom() function, which should prevent the repeated logging in attempts, which causes the page to reload endlessly.

For JFBC 3.x, update the code in the system plugin to call the function like:
if (!FB.getSession())
{
   jfbc.login.login_custom();
}

For JFBC 4.x, update the code in the system plugin to call the function like:
FB.getLoginStatus(function(response)
{
  if (response.status !== 'connected')
  {
     jfbc.login.login_custom();
  }
}

Hope that helps, but report back on your results.

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

None
14 years 8 months ago #13257 by Ivan
Hi alex. Ive tried the code for 3.x and it did the trick. I have one more question. How can i detect if we are in the canvas then execute this code. I know you mentione canvas support in 4.0 but is it possible to do this in 3.x for now.
The topic has been locked.
Support Specialist
14 years 8 months ago #13268 by alzander
Canvas support is in JFBConnect v3.4+ It's not in earlier versions.

In v3.4/4.0+, you can do the following to detect if JFBConnect thinks you're in a canvas or Page tab:
$canvas = JFBConnectCanvasLibrary::getInstance();
if ($canvas->get('canvasEnabled', false))
  // do something

There are additional ways to detect specifically if you're in a Canvas App or Page Tab. If you're looking for that, just let us know.

Good luck,
Alex
The topic has been locked.
Active Subscriptions:

None
14 years 8 months ago #13461 by Ivan
I tested the 3.x code and that worked. however the 4.0.1 code u gave is missing );

I tried this code on the system 4.0.1 plugin but it doesnt pop up the dialogue box.
 FB.getLoginStatus(function(response){ if (response.status !== 'connected') { jfbc.login.login_custom(); }});
The topic has been locked.
Active Subscriptions:

None
14 years 8 months ago #13522 by Ivan
Is the code correct? Anything missing? Have you tested the code above?
The topic has been locked.
Support Specialist
14 years 8 months ago #13534 by alzander
We use the getLoginStatus function in our main jfbconnect.js file, and it works during the login process we use. Obviously, check for Javascript errors, or throw alerts in to see if your code is getting executed.

Hope that helps get you started,
Alex
The topic has been locked.
Active Subscriptions:

None
14 years 8 months ago #13974 by Ivan
how can i execute this code only when inside the canvas?
The topic has been locked.
Support Specialist
14 years 8 months ago #13987 by alzander
The code to check if you're inside a canvas view is above, but I'm posting it here again:
$canvas = JFBConnectCanvasLibrary::getInstance(); 
if ($canvas->get('canvasEnabled', false)) { // do something }

Hope that helps,
Alex
The topic has been locked.
Support Specialist
14 years 8 months ago #13988 by alzander
Just to add on to that.. You'll need to use the do something area to update the JDocument and add any Javascript code that you want.
The topic has been locked.
Active Subscriptions:

None
14 years 8 months ago #14106 by Ivan
Yes I know that code works. But so far Ive only been able to get this javascript to work on the system plugin.


FB.getLoginStatus(function(response){ if (response.status !== 'connected') { jfbc.login.login_custom(); }});

Where could i implement both codes to work. I've tried to add this in the jfbclog in module but the javascript doesnt work there....
The topic has been locked.