Loading Facebook's Javascript SDK safely without overriding already loaded SDK - facebook

We are developing a Shopify app which is loading FB JS SDK. We load our app's JS using the Shopify's ScriptTag API which injects our JS into the Shopify's site.
Everything works well when our's is the sole app which loads the FB JS SDK. But here is the issue:
If there is another app or the shopify store itself loads the FB SDK and calls FB.init, we face 2 problems:
We want to trigger our code's window.fbAsyncInit function. Whats the best way to detect if fbAsyncInit has already executed.
Can we call FB.init again with our AppID? What are the side effects of doing so? If we cant re initialize with our AppID is there any workaround this problem where our app can co exist with an app which is already loaded?

Related

Is it possible to create multiple facebook SDK instances on a single page without conflict?

I'm working on an application that can be embedded in other pages using an iFrame that requires facebook permissions. The problem is we're running into issues when trying to use the facebook SDK to login from inside an iFrame on iOS (the login window never appears). We're running code on the parent page that places the iFrame, so my question is, can I place our SDK on the parent page without conflicting with any existing Facebook SDKs on that page?
can I place our SDK on the parent page without conflicting with any existing Facebook SDKs on that page?
No, you can’t. The JS SDK can only be embedded and initialized once.
The problem is we're running into issues when trying to use the facebook SDK to login from inside an iFrame on iOS (the login window never appears)
The whole JS SDK popup login flow is not the most suitable for mobile in many cases.
You might have better luck implementing the manual login flow, https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow
If you open that in a new window, you’d have to find a way to close it again, and have the iframe notified that successful login has happend. (Perhaps postMessage before closing the login window.)
Another possible option would be to redirect in the top window (instead of opening a new window/popup), and then after login back to the 3rd-party site, that loads your iframe again. (But not all people using your plugin on their page might like that.)

Full Facebook PHP SDK app (no JS SDK). Is it even possible?

In my work we often need to build Facebook apps in the form of Facebook Canvas and Website. These apps are available on Facebook direclty (an iframe) and as mobile versions (outside Facebook, in the browser).
We are working with a code base which mixes Facebook JS SDK (authentication and authorization) with PHP SDK (API calls). I find it rather dirty, and not easy to understand for people freshly working on the projects.
It's inconvinient to make API calls with JS, and making them with PHP forces extending access tokens. Authenticating user with JS SDK involves client-side redirects which are ugly to be honest, as they usually occur moments after the current page starts rendering, and so on...
I googled a lot about separating these two SDKs but did not find a clear answer to my questions:
Is it possible to create Facebook app (Canvas, Website) which bases ONLY on PHP SDK? Check login status, login, permissions, making API calls, etc. Would signed request be enough?
Is JS SDK the only full-proof way to determine user's login status at any time?
This link seems to describe what I'm thinking of, however the docs are rather brief (which seems to be a problem of Facebook documentation in general). Can anyone suggest other sources that might help? Does anyone have experience with builing FB aplications based only on server-side?
Thanks.
EDIT:
The link I posted above covers the case of not using ANY SDK, so no, it's not what I'm looking for.
You can even create an App WITHOUT any SDK - with simple CURL calls, for example. So yeah, it is indeed possible to use the PHP SDK only, but the login process is much better with the JS SDK (no redirection needed) and you can´t auto-refresh a user session like it is possible with FB.getLoginStatus afaik.
In short, i would not recommend it, the JS SDK is the very best way to authorize users and refresh Access Tokens. I would only use the PHP SDK (or simple CURL calls) for stuff that MUST happen on the server, and for stuff that includes using the App Secret, for example.

How do I handle the Firebase Simple Login for facebook callback in phonegap?

Building first firebase app using phonegap and angularjs. It authenticates fine in Chrome and I get back the fb user id.
My problem is when I build it with phonegap 2.9 and login with facebook I get nothing but a white screen after login.
My limited understanding is that I'm probably not handling the callback correctly.
In my console logs I see:
Finished load of: https://auth.firebase.com/auth/facebook/callback/?firebase=mementomori
&internalRedirect=false&code=AQDLp_n5_JCnC4yc1OXcXhd2Xfty_UHy_2bmOpR
-JIbyeEZQfh9LCf02deQkXbtXQknxYpTf_XHGFiy4DB1S4Do6fILTmFZ2_z
-S_N872VhwtlWkkOam4I9iMKoqa8PF43jIIdfvTpg8CwPZMs3YrVwqwuJRKzkovBL6nWI8vtdSa
_CFnEhHanXHoaJ3mH7d2vmbhmNGusBkfRdqXnd3LEC1rUyY7hrEr4pfN3BCRAzzgY_
YTot0CUoqRImLPAI76qc18KWaCytZ0ueaMnH7zavkvNExpVSiKlPQBdLUQmFmZQa
FQc6gNWm3dfZTAJw9hLg#_=_
Can anyone offer any information on how I should handle this callback properly?
Solution
I got around my issue by logging in with the native phonegap fb plugin and then passing the auth tocken to firebase for authentication.
If you're using Firebase Simple Login with Phonegap, there are a few prerequisites:
You've included phonegap.js or cordova.js in your application.
Enabled the InAppBrowser plugin in your application.
With both of the above configured, Firebase Simple Login will behave equivalently in PhoneGap as in on desktop / web, where the callback you passed to the Simple Login constructor is invoked with login error or user object. Hope that helps!

Login to facebook in a as3 application

I've been trying to get my as3 application to connect to facebook using it's SDK for flash. However most tutorials on internet talk about using php, js or flex.
Is there any way to login to facebook using only as3?
I wouldn't go near Adobe's swc for Facebook
Adobe doesn't maintain it, and since it simply maps the JS API and call it via ExternalInterface, you are better off implementing FB calls in your HTML in JS and call them yourself from AS3 via ExternalInterface.This ensures you will be using the latest JS API and not have a broken code everytime Facebook changes something.When Facebook changes something in their API you can update your JS code rather then be left helpless hoping that Adobe would allocate resources to update the Facebook swc.In short, using the native JS API is smoother. Good Luck!

Load Javascript SDK outside Facebook App

I am working on a use case suggesting some Facebook user may invite his friends to use a given Facebook app, regardless of whether this user is using the App or not. This implies invoking dialogs from the Facebook JS SDK outside of the App Canvas.
Simply including the script path in the remote page would have been too easy. So my question is, is it programmatically possible to load the JS SDK from an arbitrary domain ?
So my question is, is it programmatically possible to load the JS SDK from an arbitrary domain ?
Of course it is – countless websites use it, outside of Facebook.
You might have to specify the domain in your app settings, though. Otherwise Facebook will not allow features like f.e. login/connecting to the app from really “arbitrary” domains.