I want to call Google Plus callback function when clicking on the Google Plus button I want to call Google Plus callback function when clicking on the Google Plus button codeigniter codeigniter

I want to call Google Plus callback function when clicking on the Google Plus button


In the signinCallback(authResult) function, you should at first check if the user is signed in and then you should check, if the method value is AUTO or PROMPT. PROMPT is exactly what you want because it is returned when user clicks on the sign in button. Here's the code:

function signinCallback(authResult) {  if (authResult['status']['signed_in'] && authResult['status']['method'] == 'PROMPT') {      // User clicked on the sign in button. Do your staff here.  } else if (authResult['status']['signed_in']) {      // This is called when user is signed in to Google but hasn't clicked on the button.  } else {      // Update the app to reflect a signed out user      // Possible error values:      //   "user_signed_out" - User is signed-out      //   "access_denied" - User denied access to your app      //   "immediate_failed" - Could not automatically log in the user      console.log('Sign-in state: ' + authResult['error']);  }


From the docs, it looks like the signin button, when used this way, will always attempt an immediate validation. Since you're already signed in to google and have authorized the app, google automatically signs you in and sends you to your dashboard.

I'd suggest not using that sample code. You could, instead, use other parts of the Google Javascript API (https://developers.google.com/+/web/api/javascript) Make a Google sign in button that's a normal button. When that's clicked, call gapi.auth.authorize() to log the user in. Then nothing happens until they click the button, and when they do, it either asks for approval/login or just signs the user in automatically.