Adding google plus login to ionic app

I am trying to add google plus login to my ionic app. Following this link gives me an error.

https://ionicthemes.com/tutorials/about/google-plus-login-with-ionic-framework

Error is : cannot read property googleplus of undefined.

Here is my app.js:

.run(function($ionicPlatform) {
   $ionicPlatform.ready(function() {

    if (window.cordova && window.cordova.plugins.Keyboard) {
    cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
  cordova.plugins.Keyboard.disableScroll(true);

}
if (window.StatusBar) {
  // org.apache.cordova.statusbar required
  StatusBar.styleDefault();
}
});
})

Solution 1:

Steps to Configure authentication in Device(android)

  1. ionic start newApp
  2. ionic platform add android
  3. cordova plugin add cordova-plugin-inappbrowser
  4. bower install ngCordova
  5. bower install ng-cordova-oauth -S
  6. include both script into index.html above cordova.js

    <script src="lib/ngCordova/dist/ng-cordova.min.js"></script>
    <script src="lib/ng-cordova-oauth/dist/ng-cordova-oauth.js"></script>
    <script src="cordova.js"></script>
    
  7. Dependency injection

  8. include below code

    $scope.googleLogin = function() {
    console.log('In My Method');
    $cordovaOauth.google("Client ID", ["https://www.googleapis.com/auth/urlshortener", "https://www.googleapis.com/auth/userinfo.email"]).then(function(result) {
        console.log(JSON.stringify(result));
        // results
    }, function(error) {
        // error
        console.log('In Error');
        console.log(error);
    });
    }
    
  9. add button to view file and call the function

Solution 2:

1 first add inappbrower in your app

2 create app id for google console https://console.developers.google.com

a: create new project

b: click on Credentials

c: choose web application

d: set redirect path if u have if not than set http://localhost/callback

e: click on create button than a pop up appear save those id after that add following code

NOTE:Please change your app id and secret id in code

$scope.loginGoogle = function() {
	var requestToken = '';
	var accessToken = '';
	var clientId = '1018908884240-futc1bfc681kl2jegi3a7nn1m28aem1o.apps.googleusercontent.com';
	var clientSecret = 'KRQGDwu_llvagUucKM9oLZ7I';
            var deferred = $q.defer();
            $cordovaOauth.google(clientId, ['email']).then(function(result) {
                  $localStorage.accessToken = result.access_token;
                deferred.resolve(result.access_token);

            $http.get('https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=' + $localStorage.accessToken, {

                params: {
                    format: 'json'
                }
            }).then(function(result) {
	console.log(JSON.stringify(result));
	var id =result.data.id;
        
       deferred.resolve(result.data);
            }, function(error) {
                deferred.reject({
                    message: 'here was a problem getting your profile',
                    response: error
                });
            });


            }, function(error) {
                deferred.reject({
                    message: 'There was a problem signing in',
                    response: error
                });
            });
}