I have used a Google Plus button in my project [built in CodeIgniter]. Here I have added the following code.
<span id="signinButton">
<span
class="g-signin gooConnect"
data-callback="signinCallback"
data-clientid="my_project_client_id"
data-cookiepolicy="single_host_origin"
data-requestvisibleactions="http://schemas.google.com/AddActivity"
data-scope="https://www.googleapis.com/auth/userinfo.email">
</span>
</span>
Then I added the Javascript code provided by Google.
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/client:plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
function signinCallback(authResult) {
if (authResult['access_token']) {
$.ajax({
url:base_url+'index.php/user/getUserProfile',
type:'POST',
data:{'access':authResult['access_token']},
beforeSend : function(){
$("#loadingImageBeforeResult").show('slow');
},
success : function(resp){
$("#loadingImageBeforeResult").hide('slow');
if( resp == 'exist' ){
window.location.href=base_url+'index.php/user/my_deals';
} else {
$('#link_for_geniepage').trigger('click');
}
},
error : function(resp){}
});
} else if (authResult['error']) {
// There was an error.
// Possible error codes:
// "access_denied" - User denied access to your app
// "immediate_failed" - Could not automatially log in the user
// console.log('There was an error: ' + authResult['error']);
}
}
</script>
It's working fine for me, but if I log in my Gmail account in a separate tab and then I go to my login page, the callback function just auto logins with my Gmail credentials and redirects me to my dashboard.
I want that unless I click on that Google Plus button, the callback function should not work. How can I do this? Please help me.