Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the javascript SDK from a desktop application

I'm writing a desktop application to interact with facebook by using an embedded browser which is running HTML \ javascript from local files.

I was able to use the login dialog to retrieve a token (using the method described in the facebook documentation for desktop applications), but i'm still failing call basic SDK functions, such as FB.init() and FB.getLoginStatus().

When executing FB.init():

    FB.init({
        appId: '120260327220',
        status: true, // check login status
        oauth: true // enable OAuth 2.0
    });

I get the HTTP response (through HTTP sniffer):

<span>Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed by the Application configuration. It must match one of the Connect or Canvas URLs or domain must be the same as or a subdomain of one of the Application&#039;s base domains.</span>

And when executing FB.getLoginStatus():

        FB.getLoginStatus(function (response) {
            if (response.authResponse) {
                alert("logged in and connected user, someone you know");
            } else {
                alert("no user session available, someone you dont know");
            }
        });

i get nothing!

The application is completely client based, meaning i have no server side, thus there's no URL to register the facebook application with. Running on IE.

Does anyone know if and how i can use the facebook javascript SDK from a local javascript file (for desktop application)?

EDIT: configuring the application URL to be http://localhost is not a valid option, since eventually this script should be able to run on any machine, whether localhost is configured or not.

Thanks.

like image 677
Bagelzone Ha'bonè Avatar asked Sep 19 '11 13:09

Bagelzone Ha'bonè


People also ask

Can we use JavaScript in desktop application?

js can be used for building web, mobile, and desktop applications. Although it does not build desktop apps on its own, it can be used with Cordova or other similar tools to produce them.

What is JavaScript SDK used for?

The AWS SDK for JavaScript supports three runtimes: JavaScript for browser, Node. js for server, React Native for mobile development. It also supports cross-runtime: a service client package can be run on browsers, Node. js, and React-Native without code change.


2 Answers

Related:

The JS SDK is designed to be used on websites (per definition served and accessible over http or https) and we do not plan to support the use of file: or any other protocols. This is consistent with plugins in general, where http/https URIs are usable as identifiers (open graph amongst others), but where file:// URIs are not.

You can try initializing the SDK inside a web accessible document including using an iframe - note then that you will have to add logic to ensure correct resizing.

As an answer to a Facebook bug report.

like image 107
user362515 Avatar answered Oct 24 '22 22:10

user362515


As you mentioned that you have an embedded browser within your Desktop app so in this case what you can do is host the app's page that has facebook related functionality over the web and pull this same page's url inside your embedded browser. This way you will be able to provide a valid domain in app's settings and not localhost. Also you can make valid calls to facebook APIs from your page and your Desktop app can then make use of all these facebook related data as they are being pulled onto your embedded browser.

In a nutshell your Desktop app will be much like the Facebook's canvas where the app's page is pulled and displayed inside the canvas. However in your case you will be having a complete control of how, when, where and which parts of the page gets displayed and moreover a properly glued and well structured UI will make the external page and Desktop app blend together and users will never come to know the difference.

like image 44
eMAD Avatar answered Oct 24 '22 22:10

eMAD