Deepa Deepa - 4 months ago 148
AngularJS Question

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();
}
});
})

Answer

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