Topic-icon Auto detect if in facebook canvas then execute connect click

Active Subscriptions:

None
Alex,

I posted this a while ago : www.sourcecoast.com/forums/jfbconnect/jf...canvas-system-plugin


I had code in the system plugin where it would detect if in the canvas then it would auto execute the click so when the site load it would prompt for permissions.
Where in the code can i detect if i am in the facebook canvas. Can you let me know what code detects in canvas and where in the plugin i could apply this to.


Ivan
The topic has been locked.
Support Specialist
The code for checking for the Canvas is in the /components/com_jfbconnect/libraries/provider/facebook.php file. In the onAfterRender function, around line 397 is:
if ($fbCanvas->get('canvasEnabled', false))
That check right there is looking if the site is being loaded through the canvas and you can put more code in that block or some other section.

I hope that helps,
Alex
The topic has been locked.
Active Subscriptions:

None
Hi Alex,

I went to components/com_jfbconnect/libraries/provider/facebook.php and where the check for canvas url is i added:

  if ($fbCanvas->get('canvasEnabled', true))
           $subs .= "jfbc.login.provider('facebook');";

So when you are a new user and you go to the app this will prompt for permissions since we have not connected. I give email then the 2nd dialogue box for permissions then it takes me to the loginregister page and it keeps reloading the Connecting with Facebook Pop Up.


I basically want to prompt for user permissions and auto connect. What code can I add.

Also I also have modified code in components/com_jfbconnect/includes/jfbconnect.js
//if (!jfbc.login.logged_in)
                //    jfbc.login.facebook_onlogin();
                //else
                //    jfbc.permissions.fetch();
                if (!jfbc.login.logged_in) 
                    jfbc.login.facebook_onlogin(); 
                else 
                { 
                    jfbcJQuery(document).one("jfbc-permissions-fetched", function () { 
                        location.reload(true); 
                        }); 
                    jfbc.permissions.fetch(); 
                }



The above I have commented what should be there with the rest as my modification. Do you think this would affect it ?
The topic has been locked.
Support Specialist
You wouldn't want to edit the $subs variable. That's a special thing just for initializing the Facebook Javascript.

You'd want to create a new variable and add it to the $javascript variable at the bottom of that function so that it executes after the Facebook Javascript library has loaded.

I don't think you'd need to modify the Javascript at all. Is there a reason you need to?

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

None
Alex i tried this:
       $fbCanvas = JFBConnectProviderFacebookCanvas::getInstance();
        
    /** CODE EDIT - Auto Connect If in FB Canvas  **/
    if ($fbCanvas->get('canvasEnabled', false))
    {
    $autoclick = "<script type=\"text/javascript\">jfbc.login.provider('facebook');</script>";
    }

And at the bottom :
EOT;

     $javascript .= $autoclick; 

The script is rendered when i do a view source but the function isnt executed.


Ivan
The topic has been locked.
Support Specialist
Alright, I just did some testing. I was incorrect about the $subs code before. That actually is a good place to put the Javascript. That block will execute only after the Facebook Javascript library has loaded, which is what you want. Ultimate, you want the the $javascript var to have:
window.fbAsyncInit = function() {
    FB.init({{$version}{$appIdCode}{$status} cookie: true, xfbml: {$xfbml}});{$subs}{$resizeCode}
    jfbc.login.provider('facebook');
    };
That can be done with the $subs variable or by adding it to your own variable.

With that said, I just tested that code, and most browsers will not let that work. The jfbc.login.provider('facebook') call will have Facebook use a popup on the page. If a user hasn't clicked something on the page, almost all browsers consider that an unwanted popup and will block it. Popups are usually only shown when a user takes an action that starts the Javascript that leads to that popup.

One alternative is to turn off the "Show 'login credentials' in popup" setting in the JFBConnect -> Facebook area. That will force the user through the server-side authentication flow, instead of the popup flow. That may not be what you're looking for though if you want just a popup to show.

Test with the above and see how it goes. Most browsers will let you bypass the popup blocker to test, but you wouldn't be able to use that on a live site since most users won't unblock it.

Alex
The topic has been locked.