Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Facebook login to ionic app

I am newbie to a Angular and Ionic as well.

Tried the following tutorial:

https://www.sitepoint.com/how-to-integrate-facebook-login-into-a-cordova-based-app/

Steps performed: 1.In app browser is installed.

  1. Included libraries.

    <script src="lib/ngCordova/dist/ng-cordova.js"></script>
    <script src="lib/ng-cordova-oauth/dist/ng-cordova-oauth.js"></script>
    <script src="cordova.js"></script>
    
  2. Include code inside index.html before body closing tag:

    <script>
       window.fbAsyncInit = function() {
        FB.init({
        appId      : 'MyappID',
        xfbml      : true,
        version    : 'v2.6'
      });
    };
    
      (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 = "//connect.facebook.net/en_US/sdk.js";
         fjs.parentNode.insertBefore(js, fjs);
         }(document, 'script', 'facebook-jssdk'));
    </script>
    
  3. Following is my login.html :

     <button class="btn-margin-left button button-positive" ng-click="menuCtrl.fbLogin()">
      <i class="ion-social-facebook icon-size1 "></i>
     </button>
    
  4. This is my controller :

    menuCtrl.fbLogin = function ($cordovaOauth,$http) {
        facebookLogin(window.cordovaOauth, window.http);
    }
    
  5. This is my app.js :

    angular.module("cgsi",['ionic', 'ngCordova','ngCordovaOauth'])
      .config(function($stateProvider, $urlRouterProvider, $ionicConfigProvider, $httpProvider, $logProvider, $sceDelegateProvider,$cordovaOauth,$http) {
      window.cordovaOauth = $cordovaOauth;
      window.http = $http;
     });
    

I am getting error Unknown provider $cordovaOauth Please let me know where i am going wrong?

like image 822
Deepa Avatar asked Mar 03 '26 14:03

Deepa


1 Answers

first of all you need to have account as facebook developer and generate one app for test,

https://developers.facebook.com/

then create one cordova application and and set one button in UI side.

Then you need to install following plugin in your test-app.

https://github.com/Wizcorp/phonegap-facebook-plugin

or

https://github.com/jeduan/cordova-plugin-facebook4

please go through above plugin carefully because you need to add your app_id and app_name which you can find from developer-facebook account where you created your test app.

and then you need to go through related plugin documentation for getting facebook login code.

Thank you.

like image 124
Naitik Avatar answered Mar 06 '26 04:03

Naitik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!