What's the best approach to integrate Ionic with Facebook?

I would like to know if there is a clean way to integrate an existing Ionic application with facebook android sdk. I know there are a few posts about this topic, but none of them lead to the right answer.
I tried several ways, among them Phonegap Facebook Plugin, none of them fully worked. Has someone succesfully integrated them?
Maybe someone could explain me how to make Facebook native Android SDK and Javascript SDK coexist in the same application.

Well, I think I finally got it, in these days I will post the best approach I found to integrate Ionic with Facebook SDK (for Android, I didn’t test it with iOS).
It allows the developer to test the app both locally and on the device, using a service wrapper of the Facebook api.

Hi everyone,

Ok, in this github repo branch you will find the solution I came up to Facebook Ionic integration.

On this guide Facebook Cordova Integration you will find a detailed explanation of the process.

However, I have to warn you, it’s not entirely finished the way I would like. I couldn’t get the mobile app to use the native Facebook app. Any help with that will be very appreciated.

I think the most important thing here is that you can test your app in the browser as well as in the device. That was the obstacle I was tackling from the beggining.

Please if you have any question feel welcome to ask, that way I can improve my solution and the guide :smiley:

I have been having trouble implementing your Facebook cordova integration guide for iOS. I feel like I have tried everything. What alternate steps would you recommend when doing this for iOS instead of Anroid?

For starters I would look at phonegap-facebook-plugin documentation on iOS. (I know it’s awfully documented, but it’s what we have…)
The iOS configuration is different from Android’s.
Anyway, I believe this week I’ll be having to integrate Ionic with FB SDK for iOS.
I’ll keep you posted.

Thanks, looking forward to it. I’ll do the same.

Hi everyone, the plugin has released a new version with some major changes.
On these days I’ll update my repo with the latest version.

accurso_alan… do you have problem of facebook logout problem when using above phonegap-facebook-plugin

“Refused to display ‘https://www.facebook.com/home.php’ in a frame because it set ‘X-Frame-Options’ to ‘DENY’.”

Hi @stevegreat,
It’s been a while since I made this post and I’m afraid I’m not up to date with the FB plugin progress (since the mobile project I was working on is on standby).
However, I would investigate another alternative to integrating Ionic with FB, like Coenraets OpenFB, until a stable release of the plugin is released.

Thank you. most of facebook plugins works well in “login”. The problem is if it can totally logout and destroy the session.

Even the plugin like http://coenraets.org/blog/2014/04/sociogram-angularjs-ionic-facebook/ not able to solve logging out of facebook totally.

Some facebook plugin work well without ionic and can logout correctly. but when integrating with ionic it cause problem. Thanks though, once I found out the problem, I will posted back to the forum.

— Sample facebook logout that will destroy the session and cookies
Facebook logout require calling “https://www.facebook.com/logout.php?access_token=ACCESS_TOKEN&app_id=APPID&channel_url=http%3A%2F%2Fstatic.ak.facebook.com%2Fconnect%2Fxd_arbiter%2FdgdTycPTSRj.js%3Fversion%3D41%23cb%3Df2e36ae79c%26domain%3Drun.plnkr.co%26origin%3Dhttp%3A%2F%2Frun.plnkr.co%2Ff6eb1eb14%26relation%3Dparent.parent&display=hidden&e2e={}&locale=en_US&next=http%3A%2F%2Fstatic.ak.facebook.com%2Fconnect%2Fxd_arbiter%2FdgdTycPTSRj.js%3Fversion%3D41%23cb%3Df229ffc204%26domain%3Drun.plnkr.co%26origin%3Dhttp%3A%2F%2Frun.plnkr.co%2Ff6eb1eb14%26relation%3Dparent%26frame%3Df523faf0c&sdk=joey

Hey there!
Out of curiosity, why would you want to logout your user from facebook?
If I were the user I wouldn’t expect that behaviour of a logout action in an application.
Maybe you should think of separating application logout (session disposal) vs facebook logout (which leads to the user being logged out of facebook).
Or perhaps I didn’t understand well the issue.

In the scenario where one device use by several people. like ipad, ipad mini, tablet, etc.
hmmm… good idea of “separating application logout (session disposal) vs facebook logout”. Probably useful in the future. However, if I logout from session, in order for the user to “switch to another facebook user”. it still have problem in of “facebook cookies retaining in inappbrowser” and for mobile device not like desktop there is no “switch user in login menu”.

If there is a way to have switch user in login menu when popping up facebook. it might be a good enough solution to solve it

1 Like

Hey all,

Has anyone been able to successfully get the phonegap-facebook-plugin working with ionic? I even tried @accurso_alan’s github project “CostSplitter” working to no avail. Seems as though the plugin is currently broken so I used release 0.4.2. I’m just not able to really understand the process since the documentation is pretty bad and there’s so much conflicting information. I’m going insane trying to figure it out.

Same problem.

Has anyone been able to successfully get the phonegap-facebook-plugin working with ionic?

1 Like

I actually did eventually got it working. The current master works pretty well, and their documentation has improved. Basically add the plugin after adding your platforms (iOS/Android). You need to open the Android project and set the facebookLib as a library. You might have to add the facebook app ID in the iOS plist manually (I forget).

Then you need to wrap the facebookConnectPlugin.js in an angular module and include it in your index.html.

Then I basically hacked it in with the following…

.controller('MyCtrl', function ($window, $scope, $state, FacebookConnectPlugin) {
        if(!$window.cordova) {
            //Implement in browser... Still kinda broken since it uses cookies to store access token
            //in the browser facebookConnectPlugin GLOBAL won't be set. So use our angular module. Probably a better way to do this.
            $window.facebookConnectPlugin = FacebookConnectPlugin;
        facebookConnectPlugin.login( ["email","user_friends"],
            function (response) {
                //Actually useless. Do whatever you want with the access token
                $window.localStorage['fbtoken'] = response.authResponse.accessToken;
                //Get user profile
                        //Get user picture
                                fbuser.img = result.data.url;
                                //Do stuff with fbuser
                                alert('Something bad happened. Please try again later. '+error);
                        alert('Something bad happened. Please try again later. '+error);
            function (error) {
                alert('Something bad happened. Please try again later. '+error);

Then build and spend the next 2 hours fixing errors.

Let me know if you run into anything. I know this is really frustrating. I’ve been thinking about publishing an example app on github but my time is limited.


Has anyone else tried the Social Sharing Cordova plugin? I haven’t had any luck yet - the build process isn’t adding the JS–configure and build.xml don’t get changed when I do cordova prepare. Looks like it’d fit all my needs. If it worked…

If you’re still willing to share your implementation I’d love to see it. Have given up implementing the phonegap-facebook plugin multiple times but the recent improvements in documentation have me hopeful.

I ended up using the fantasic ngCordova plugin. They drifty guys wrapped a bunch cordova plugins with angular wrappers, which makes them really easy to use. Let me know if you need anymore info!

Agree with using ngCordova - It was much easier to get working than the Cordova Plugs in Telerik Appbuilder

Yeap. Have it working on my ionic app.