Initiate Google sign in on button click

前端 未结 2 1234
心在旅途
心在旅途 2021-01-17 10:39

Hello I am using google api to sign in to my web application . Now Its working fine . But the problem is the sigin is initiated automatically as I go to my log in page . But

2条回答
  •  不思量自难忘°
    2021-01-17 11:40

    Best way is to use Java Script to sign in to google as I have found out .

    use

    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.js?onload=onLoadCallback';
           var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
         })();
    
    

    to initialize js . And finally call below method to sign-in user

    function login() 
    {
      var myParams = {
        'clientid' : 'YOUR_CLIENT_ID.apps.googleusercontent.com', //You need to set client id
        'cookiepolicy' : 'single_host_origin',
        'callback' : 'loginCallback', //callback function
        'approvalprompt':'force',
        'scope' : 'https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.profile.emails.read'
      };
      gapi.auth.signIn(myParams);
    }
    

    By using this I was able to solve this problem . Now User needs to click on sign-in to login

提交回复
热议问题