Adding Facebook login to ionic app

情到浓时终转凉″ 提交于 2019-12-21 21:24:47

问题


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?


回答1:


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.




回答2:


I can't see your controller has dependency injected or not, I hope you will get what my mean.

if still problem is same. use Adding google plus login to ionic app

And instead of google try facebook. after completion of installation you can add all other plugins that you want.



来源:https://stackoverflow.com/questions/37569241/adding-facebook-login-to-ionic-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!