Connecting to the Facebook API from Electron


#1

Can anyone help me out with getting connected to the FB API? I’ve created a FB app and inserted my appID in FB.init( ). I keep getting the “Given URL is not allowed by the Application configuration: One or more of the given URLs is not allowed by the App’s settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App’s domains.” error. I’m assuming this is because I am running electron on localhost and I can’t figure out what the correct domain is. I’m probly just being dense here, but I’m stuck.

window.fbAsyncInit = function() {
  FB.init({
    appId      : 'my-app-ID',
    cookie     : true,  // enable cookies to allow the server to access 
                        // the session
    xfbml      : true,  // parse social plugins on this page
    version    : 'v2.2' // use version 2.2
  });

  FB.getLoginStatus(function(response) {
    statusChangeCallback(response);
  });

  };

  // Load the SDK asynchronously
  (function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "https://connect.facebook.net/en_US/sdk.js";
    fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));


Facebook login auth
Facebook OAuth web flow problem
Facebook OAuth web flow problem
Facebook api
#2

Same problem here. Did you find any solutions for it?

I found this messenger app https://github.com/sindresorhus/caprine where a fb login is integrated. By checking the main js file (https://github.com/sindresorhus/caprine/blob/master/index.js) it seems to be needed set certain properties for the ‘webPreferences’ object of your BrowserWindow:

webPreferences: {
// fails without this because of CommonJS script detection
nodeIntegration: false,
preload: path.join(__dirname, 'browser.js'),
// required for Facebook active ping thingy
webSecurity: false,
plugins: true
}

I’m still getting an error that ‘Given URL is not ping?client_id=MY_ID&domain=&origin=1&redirect_uri=http%3A%2F%2Fstaticxx.facebook.com%2F…:1 Given URL is not allowed by the Application configuration:’ So it seems that i need to configure some special stuff on the facebook settings page, but i can’t find what exactly. Tried already almost every possible setting :confused:

MY_ID is of course a real app id :wink:


#3

Is there a solution for this?


#4

redirect_uri. The URL that you want to redirect the person logging in back to. This URL will capture the response from the Login Dialog. If you are using this in a webview within a desktop app, this must be set to https://www.facebook.com/connect/login_success.html. You con confirm that this URL is set for your app by going to the App Dashboard, clicking Facebook Login in the right-hand menu, and checking the Valid OAuth redirect URIs in the Client OAuth Settings section.


#5

Hi, I setup the redirect_uri as mentionned, but I’m still getting error message about the url domain…
Can’t set the domain to 127.0.0.1 and I really don’t see what I can use as domain.


#7

Did you solved this problem?


#8

You cannot use JavaScript SDK on building a desktop application. Alternatively, you should build login flow manually using browser redirects. Details are shown in the following link.(https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow)
Note that redirect_url must be set to https://www.facebook.com/connect/login_success.html and this url must be included in the Valid OAuth redirect URIs in the Client OAuth Settings that appears after adding Facebook Login by clicking Add Product on the left side menu.


#10

Can somebody provide any examples please !


#11

Here’s how I did it: https://github.com/openwhyd/openwhyd-electron/blob/1ea854d9a0f80a51b5f1270d91f2c0c646d62392/src/main.js