Facebook login with Ionic/Angularjs?

Asked

Viewed 350 times

2

I’m trying to log in to facebook with Ionic/Angularjs.

Whenever I try to login returns this error:

Object {errorMessage: "User cancelled dialog", errorcode: "4201"}

I’m following this example: Login Facebook with Ionic

How to solve this problem ?

var app = angular.module("starter");

app.controller("MainCtrl", function($scope, $state, $ionicHistory, $ionicLoading){

  // This is the success callback from the login method
  var fbLoginSuccess = function(response) {
    console.log("cliquei");
    if (!response.authResponse){
      fbLoginError("Cannot find the authResponse");
      return;
    }

    var authResponse = response.authResponse;

    getFacebookProfileInfo(authResponse)
      .then(function(profileInfo) {
      console.log("Email profile " + profileInfo.email);      
      $ionicLoading.hide();      
    }, function(fail){
      // Fail get profile info
      console.log('profile info fail', fail);
    });
  };

  // This is the fail callback from the login method
  var fbLoginError = function(error){
    console.log('fbLoginError ', error);
    $ionicLoading.hide();
  };

  // This method is to get the user profile info from the facebook api
  var getFacebookProfileInfo = function (authResponse) {
    var info = $q.defer();

    facebookConnectPlugin.api('/me?fields=email,name&access_token=' + authResponse.accessToken, null,
      function (response) {
        console.log(response);
        info.resolve(response);
      },
      function (response) {
        console.log(response);
        info.reject(response);
      }
    );
    return info.promise;
  };
});
  • Where is the code ?

  • @devgaspa mals ! posted the code.

  • What version of Ionic/Angularjs are you using ?

  • Ionic 1.1.1 and angular 1.4.7.

  • Sure? you checked the Ionic-Bundle script for the version? Sometimes, when you install via npm it happens to come earlier versions. And I believe this mistake is happening for this reason.

  • check yes @devgaspa Ionic eh 1.1.1 and angular 1.4.7.

Show 1 more comment

1 answer

0


Browser other questions tagged

You are not signed in. Login or sign up in order to post.