Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Facebook PHP Access Token with FB Javascript SDK for FB.UI dialog

I am trying to have a FB.ui dialog box appear on button click for a user. Right now, I can get the dialog box to appear as a pop up, but I do not want this. I want the dialog box to appear as a modal, so that pop-up blockers don't block it. I have tried using the "display: 'iframe'" parameter, but when using this I get the error:

"dialog" mode can only be used when the user is connected.

I have read that perhaps I need to use an access token to get this to appear as a modal and use the display iframe parameter. Keep in mind this is for a website.

I already have an OAuth2 package in Laravel on the server side (PHP) that takes care of authenticating the Facebook user, and pulls an access token. My question is, how do I pull this token and apply it to the Javascript SDK so I can have the FB.ui dialog appear as a modal? Do I even need to do this? Here is the javascript I am using:

window.fbAsyncInit = function () {
    FB.init({ appId: '************', cookie: true, status: true, xfbml: true, oauth: true });
    if (typeof facebookInit == 'function') {
        facebookInit();
    }
};
(function(d){
    var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
    js = d.createElement('script'); js.id = id; js.async = true;
    js.src = "//connect.facebook.net/en_US/all.js";
    d.getElementsByTagName('head')[0].appendChild(js);
}(document));

function facebookInit() {
    FB.ui({
        url : 'http://url.com',
        method: 'feed',
        name: 'Url',
        link: url,
        display: 'iframe',
        picture: 'http://thisimage.png',
        caption: fb_description,
    }, function (response) {
        if (response && response.post_id) {
            window.location = "/artists";
        } else {
            window.location = "/artists";
        }                   
    });
}
like image 371
user1072337 Avatar asked Nov 11 '22 09:11

user1072337


1 Answers

I also had this issue - it turned out I didn't have the localhost domain specified on my Facebook app settings. After I added it, it worked fine.

enter image description here

like image 177
Constant Meiring Avatar answered Nov 14 '22 23:11

Constant Meiring