title: Google-plus sign in: the code runs twice, user was logged out right after he logs in
body: <p>this is a page built on <a href="https://developers.google.com/+/web/people/" rel="noreferrer">example</a></p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Demo: Getting an email address using the Google+ Sign-in button&lt;/title&gt;
    &lt;style type="text/css"&gt;
    html, body { margin: 0; padding: 0; }
    .hide { display: none;}
    .show { display: block;}
    &lt;/style&gt;
    &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" &gt;&lt;/script&gt;
    &lt;!--&lt;script src="https://apis.google.com/js/plusone.js" type="text/javascript"&gt;&lt;/script&gt;--&gt;
    &lt;script src="https://apis.google.com/js/client:plusone.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;script type="text/javascript"&gt;
    /*
     * Triggered when the user accepts the sign in, cancels, or closes the
     * authorization dialog.
     */
    function loginFinishedCallback(authResult) {
      if (authResult) {
  
         console.log('authResult : ',authResult);
        if (authResult['error'] == undefined){
          gapi.auth.setToken(authResult); // Store the returned token.
          toggleElement('signin-button'); // Hide the sign-in button after successfully signing in the user.
          getEmail();                     // Trigger request to get the email address.
        } else {
          console.log('An error occurred');
        }
      } else {
        console.log('Empty authResult');  // Something went wrong
      }
    }
  
    /*
     * Initiates the request to the userinfo endpoint to get the user's email
     * address. This function relies on the gapi.auth.setToken containing a valid
     * OAuth access token.
     *
     * When the request completes, the getEmailCallback is triggered and passed
     * the result of the request.
     */
    function getEmail(){
      // Load the oauth2 libraries to enable the userinfo methods.
      gapi.client.load('oauth2', 'v2', function() {
            var request = gapi.client.oauth2.userinfo.get();
            request.execute(getEmailCallback);
          });
    }
  
    function getEmailCallback(obj){
      var el = document.getElementById('email');
      var email = '';
      console.log("OBJ = ",obj)
      if (obj['email']) {
        email = 'Email: ' + obj['email'];
      }
  
      //console.log(obj);   // Uncomment to inspect the full object.
  
      el.innerHTML = email;
      toggleElement('email');
    }
  
    function toggleElement(id) {
      var el = document.getElementById(id);
      if (el.getAttribute('class') == 'hide') {
        el.setAttribute('class', 'show');
      } else {
        el.setAttribute('class', 'hide');
      }
    }
    &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;div id="signin-button" class="show"&gt;
       &lt;div class="g-signin" data-callback="loginFinishedCallback"
        data-approvalprompt="auto"
        data-clientId="751931329576.apps.googleusercontent.com"
        data-scope="https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/userinfo.email"
        data-height="short"
        data-cookiepolicy="http://semicon-equip.com"
        &gt;
      &lt;/div&gt;
      &lt;!-- In most cases, you don't want to use approvalprompt=force. Specified
      here to facilitate the demo.--&gt;
    &lt;/div&gt;
  
    &lt;div id="email" class="hide"&gt;&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Question 1: It always fails with "<code>Uncaught TypeError: Cannot read property 'load' of undefined</code>", </p>
  
  <p>until I use </p>
  
  <p><code>&lt;script src="https://apis.google.com/js/client:plusone.js" type="text/javascript"&gt;&lt;/script&gt;</code> </p>
  
  <p>instead of the example code:</p>
  
  <p><code>&lt;script src="https://apis.google.com/js/plusone.js" type="text/javascript"&gt;&lt;/script&gt;</code> </p>
  
  <p>What's the difference between <code>plusone.js</code> and <code>client:plusone.js</code> ?</p>
  
  <p><img src="https://i.stack.imgur.com/NMWBE.jpg" alt="enter image description here"></p>
  
  <p>Question 2: Why the code run twice per page loads ?
  <img src="https://i.stack.imgur.com/xj6Ez.jpg" alt="enter image description here"></p>
  
  <p>Qestion 3: the user was logged out after he just signed in, how to fix ?</p>
  
  <p><img src="https://i.stack.imgur.com/Re6rR.jpg" alt="enter image description here"></p>
  
  <p><a href="http://www.semicon-equip.com/g5.php" rel="noreferrer">error demo page</a> for the above (all the errors are in the background console).</p>