amit sarma
amit sarma

Reputation: 1

Ionic 2 Google Plus Authetication

google login authentication in ionic 2 with step by step. i try to print simple response but it does not work

GLogin(){   
     alert("you are in google plush "); 
     GooglePlus.login((res)=>{       
         alert(this.data=res);   
     });
}

Upvotes: 0

Views: 264

Answers (1)

mosca90
mosca90

Reputation: 999

Add the plugin (check this link):

cordova plugin add cordova-plugin-googleplus --save --variable REVERSED_CLIENT_ID=myreversedclientid

Include the lib:

import { GooglePlus } from 'ionic-native';

Now the login:

googlePlus_login() {
    GooglePlus.login(
        {
            'scopes': '',
            'webClientId': '',
            'offline': false
        }
    ).then(
        (success) => {
            alert(  '\n id: ' + JSON.stringify(success.userId) +
                    '\n name: ' + JSON.stringify(success.displayName) +
                    '\n email: ' + JSON.stringify(success.email)
            );
        },
        (failure) => {
            console.log('GOOGLE+ login FAILED', failure);
        }
    );
}

where:

scope: optional, space-separated list of scopes, If not included or empty, defaults to profile and email.

webClientId: optional clientId of your Web application from Credentials settings of your project - On Android, this MUST be included to get an idToken. On iOS, it is not required.

offline: optional, but requires the webClientId - if set to true the plugin will also return a serverAuthCode, which can be used to grant offline access to a non-Google server.

Logout function:

googlePlus_logout() {
    GooglePlus.logout().then(
        (success) => {
            console.log('GOOGLE+: logout DONE', success);
        },
        (failure) => {
            console.log('GOOGLE+: logout FAILED', failure);
        }
    );
}

Hope it will help you. :)

Upvotes: 2

Related Questions