Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make openFB use native app for login instead of in-app-browser (ionic) #126

Open
pedromonteiro221 opened this issue May 16, 2017 · 4 comments

Comments

@pedromonteiro221
Copy link

Hello everyone, i am having some trouble with the ngopenFB (openFB)...
I followed this tutorial: https://ccoenraets.github.io/ionic-tutorial/ionic-facebook-integration.html

I wanted to make a login that when the user presses a button to login, show up a window of the native app with a button to login instead of a window in-app-browser to make user input his data to login.

What i want is this:
https://dab1nmslvvntp.cloudfront.net/wp-content/uploads/2015/12/1449042836fb-login.png

But what i have is this:
https://www.tutorialspoint.com/ionic/images/ionic-cordova-facebook.jpg

Login and logout are working perfectly fine, and im able to get onto my app user info, but i wanted to have a login that doens't need user input.

Im sorry if i didn't explain myself, I'm very new to ionic and these plugins...

@blueprin4
Copy link

i need same

@pedromonteiro221
Copy link
Author

Sorry but this plugin doens't have native login, if you want to use a good plugin that uses native login / web login use this: https://github.com/jeduan/cordova-plugin-facebook4

@Toomavic
Copy link

Could you provide a guide how to use it with ionic project?
I had read docs but still i dont know how to start

@pedromonteiro221
Copy link
Author

This is for ionic v1

First you need to create your app on developers facebook and get an AppID (you must see a guide how to configure developers facebook, i started with web app then configured it for android)

After that on your ionic project you do cordova plugin add cordova-plugin-facebook4 --save --variable APP_ID="123456789" --variable APP_NAME="myApplication" where AppID and AppName are provided when you create your app on developers facebook.

Then you basically after having all configured, code the login, getLoginStatus, logout:

$scope.fbLogin = function () {
        facebookConnectPlugin.login(['email'], function (response) {
            console.log(response);
            $window.localStorage['status'] = "fbtrue";
            $rootScope.isLogin = true;
            $state.go($state.current, {}, { reload: true });
            $scope.getFbData();
            useremail = $window.localStorage['email'];
            username = $window.localStorage['name'];
            userimage = $window.localStorage['userimage'];
            token = $window.localStorage['AccessToken'];
            console.log(token);
            $window.localStorage['log'] = "true";
        }, function (error) {
        })
    };

    $scope.getFbData = function () {
        facebookConnectPlugin.getLoginStatus(function (response) {
            if (response.status == "connected") {
                $window.localStorage['AccessToken'] = response.authResponse.accessToken;
                facebookConnectPlugin.api('/' + response.authResponse.userID + '?fields=id,name,email', [],
                function onSuccess(result) {
                    $window.localStorage['name'] = result.name;
                    $window.localStorage['email'] = result.email;
                    $window.localStorage['userimage'] = "http://graph.facebook.com/" + response.authResponse.userID + "/picture?width=80&height=80";

                    $window.localStorage['log'] = "true";
                    $rootScope.email = $window.localStorage['email'];
                    $scope.username = $window.localStorage['name'];
                    $scope.useremail = $window.localStorage['email'];
                    $scope.userimage = $window.localStorage['userimage'];
                   
                    $state.go($state.current, {}, { reload: true });
                },
                function onError(error) {
                }
                );
            } else {
            }
        }, function (error) { })
    }

$scope.Logout = function () {
        if ($window.localStorage['status'] == "fbtrue") {
            facebookConnectPlugin.logout(function (success) {
                $rootScope.isLogin = false;
                $window.localStorage['status'] = "false";
                $window.localStorage['log'] = "false";
                $window.localStorage['AccessToken'] = "";
                $state.go($state.current, {}, { reload: true });
            }, function (error) { })
        }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants