Login facebook firebase problem tokenacess ionic 1

Hello! Problems accessing facebook token with ionic 1 and firebase.!

You use the accessToken variable before you define it.

Also you post your code as images, so I can’t show you where. You have to find it yourself.

‘use strict’;

app.factory(‘Auth’, function($firebaseAuth, $firebaseObject, $firebaseArray,$state, $http, $q, $cordovaOauth) {
var ref = firebase.database().ref();
var auth = $firebaseAuth();

var Auth = {

    createProfile: function(uid, profile) {
        return ref.child('profiles').child(uid).set(profile);
    },

    getProfile: function(uid) {
        return $firebaseObject(ref.child('profiles').child(uid));
    },

    login: function() {

        var provider = new firebase.auth.FacebookAuthProvider();
        provider.addScope('public_profile, email, user_location, user_birthday, user_photos, user_about_me');

$cordovaOauth.facebook(“1455510817798096”, [“public_profile”, “email”, “user_location”, “user_birthday”, “user_photos”, “user_about_me”]).then(function(authData) {
// return auth.$facebook(provider).then(function(resp){
console.log(‘cordova facebook!’);
//$http.get(“https://graph.facebook.com”).then(function(resp) {
console.log(‘facebook cordova!’);
//add acesstoken =
//var accessToken= auth.signInWithCredential(firebase.auth.FacebookAuthProvider.credential(accessToken)).then(function(user) {
console.log(‘Facebook login succeeded’);
//
auth.signInWithCredential(firebase.auth.FacebookAuthProvider.credential(accessToken)).then(function(user) {

  console.log('token face!');
               //comentei pq token esta com problema
                var accessToken = result.credential.accessToken;
                //
                var user = Auth.getProfile(result.user.uid).$loaded();
                   console.log('auth acess, user!');
                user.then(function(profile) {
                    console.log('profile 01!');
                    if (profile.name == undefined) {
                      console.log('profile!');
                        var genderPromise = $http.get('https://graph.facebook.com/me?fields=gender&access_token=' + accessToken);
                        var birthdayPromise = $http.get('https://graph.facebook.com/me?fields=birthday&access_token=' + accessToken);
                        var locationPromise = $http.get('https://graph.facebook.com/me?fields=location&access_token=' + accessToken);
                        var bioPromise = $http.get('https://graph.facebook.com/me?fields=about&access_token=' + accessToken);
                        var imagesPromise = $http.get('https://graph.facebook.com/me/photos/uploaded?fields=source&access_token=' + accessToken);
                         
                        $q.all(promises).then(function(data) {
                            var info = result.user.providerData[0];
                            var profile = {
                                name: info.displayName,
                                email: info.email,
                                avatar: info.photoURL,
                                gender: data[0].data.gender ? data[0].data.gender : "",
                                birthday: data[1].data.birthday ? data[1].data.birthday : "",
                                age: data[1].data.birthday ? Auth.getAge(data[1].data.birthday) : "",
                                location: data[2].data.location ?  data[2].data.location.name : "",
                                bio: data[3].data.about ? data[3].data.about : "",
                                images: data[4].data.data
                            }
                          // var user = Auth.getProfile(result.user.uid).$loaded();

                            console.log('profile criar!');
                             Auth.createProfile(result.user.uid, profile);
                          
                        });
                       
                    }

                });
              
            });

}).catch(function(error) {

// console.log(‘Problema 01 login!’);
});

    },

  logout: function() {
        return auth.$signOut();
    },

    getAge: function(birthday) {
        return new Date().getFullYear() - new Date(birthday).getFullYear();
    },

    requireAuth: function() {
        return auth.$requireSignIn();
    },
    getProfiles: function(){
       return $firebaseArray(ref.child('profiles')); 
    }, 
   getProfilesByAge: function(age) {
        return $firebaseArray(ref.child('profiles').orderByChild('age').startAt(18).endAt(age));
    }   

};

auth.$onAuthStateChanged(function(authData) {
if(authData) {
console.log(‘Este usuario ja se encontra logado!’);
} else {
$state.go(‘login’);
console.log(‘Este usuario ainda nao se encontra logado no aplicativo da Cleo.’);
}
});

return Auth;

});

Please use the </> button above the post input field to format your code or error message or wrap it in ``` (“code fences”) manually. This will make sure your text is readable and if it recognizes the programming language it also automatically adds code syntax highlighting. Thanks.

type or paste code here
'use strict';



app.factory('Auth', function($firebaseAuth, $firebaseObject, $firebaseArray,$state, $http, $q, $cordovaOauth) {
    var ref = firebase.database().ref();
    var auth = $firebaseAuth();

    var Auth = {

        createProfile: function(uid, profile) {
            return ref.child('profiles').child(uid).set(profile);
        },

        getProfile: function(uid) {
            return $firebaseObject(ref.child('profiles').child(uid));
        },

        login: function() {

            var provider = new firebase.auth.FacebookAuthProvider();
            provider.addScope('public_profile, email, user_location, user_birthday, user_photos, user_about_me');
         
$cordovaOauth.facebook("1455510817798096", ["public_profile", "email", "user_location", "user_birthday", "user_photos", "user_about_me"]).then(function(authData) {
 // return auth.$facebook(provider).then(function(resp){
    console.log('cordova facebook!');
//$http.get("https://graph.facebook.com").then(function(resp) {
          console.log('facebook cordova!');
          //add acesstoken =
//var accessToken= auth.signInWithCredential(firebase.auth.FacebookAuthProvider.credential(accessToken)).then(function(user) {
     console.log('Facebook login succeeded');
  //              
        auth.signInWithCredential(firebase.auth.FacebookAuthProvider.credential(accessToken)).then(function(user) {
          
      console.log('token face!');
                   //comentei pq token esta com problema
                    var accessToken = result.credential.accessToken;
                    //
                    var user = Auth.getProfile(result.user.uid).$loaded();
                       console.log('auth acess, user!');
                    user.then(function(profile) {
                        console.log('profile 01!');
                        if (profile.name == undefined) {
                          console.log('profile!');
                            var genderPromise = $http.get('https://graph.facebook.com/me?fields=gender&access_token=' + accessToken);
                            var birthdayPromise = $http.get('https://graph.facebook.com/me?fields=birthday&access_token=' + accessToken);
                            var locationPromise = $http.get('https://graph.facebook.com/me?fields=location&access_token=' + accessToken);
                            var bioPromise = $http.get('https://graph.facebook.com/me?fields=about&access_token=' + accessToken);
                            var imagesPromise = $http.get('https://graph.facebook.com/me/photos/uploaded?fields=source&access_token=' + accessToken);
                             
                            $q.all(promises).then(function(data) {
                                var info = result.user.providerData[0];
                                var profile = {
                                    name: info.displayName,
                                    email: info.email,
                                    avatar: info.photoURL,
                                    gender: data[0].data.gender ? data[0].data.gender : "",
                                    birthday: data[1].data.birthday ? data[1].data.birthday : "",
                                    age: data[1].data.birthday ? Auth.getAge(data[1].data.birthday) : "",
                                    location: data[2].data.location ?  data[2].data.location.name : "",
                                    bio: data[3].data.about ? data[3].data.about : "",
                                    images: data[4].data.data
                                }
                              // var user = Auth.getProfile(result.user.uid).$loaded();

                                console.log('profile criar!');
                                 Auth.createProfile(result.user.uid, profile);
                              
                            });
                           
                        }

                    });
                  
                });
  

   }).catch(function(error) {
  
   //  console.log('Problema 01 login!');
});
  
        },

      logout: function() {
            return auth.$signOut();
        },

        getAge: function(birthday) {
            return new Date().getFullYear() - new Date(birthday).getFullYear();
        },

        requireAuth: function() {
            return auth.$requireSignIn();
        },
        getProfiles: function(){
           return $firebaseArray(ref.child('profiles')); 
        }, 
       getProfilesByAge: function(age) {
            return $firebaseArray(ref.child('profiles').orderByChild('age').startAt(18).endAt(age));
        }   

    };


   auth.$onAuthStateChanged(function(authData) {
        if(authData) {
            console.log('Este usuario ja se encontra logado!');
        } else {
            $state.go('login');
            console.log('Este usuario ainda nao se encontra logado no aplicativo da Cleo.');
        }
    });

    return Auth;

});

accessToken doesnt exist here.

Extremely grateful, for the tips. But since I’m a beginner I’m not sure how I could solve this problem! Su can give me more tips, I’ll be extremely happy.