3

I am trying to follow the sample example from Google's developer tutorial
using updated chrome (version 38.0)

But seems like the gapi.auth functions never reached to the their callbacks

Here is a code example that demonstrate it:

<!doctype html>
<html>
  <head>
    <title>Google API Client test</title>
  </head>
  <body>
    here will be the use of Oauth 2.0
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>  
    <script>    
    googleApiClientReady = function() {    
    window.setTimeout(checkAuth, 1);  
    }
    function checkAuth() {    
      gapi.auth.authorize({
    client_id: 'XXX',
    scope: 'https://www.googleapis.com/auth/youtube',
    immediate: true
    }, handleAuthResult);
  }
  function handleAuthResult(authResult) {  
    if (authResult && !authResult.error) {
    alert('gapi.auth return successfully');
    } else {
    alert('gapi.auth return with error');
    }
  }
    </script> 
    <script src="https://apis.google.com/js/client.js?onload=googleApiClientReady"></script>
  </body>
</html>

When I run the above html+JS file- none of the 2 optional alerts of 'HandleAuthResult' are displayed on screen at all - meaning that this function is not called back by 'gapi.auth.authorize'

Did anyone manage to use this library properly?

GyRo
  • 2,586
  • 5
  • 30
  • 38

1 Answers1

0

First of all you need to check if chrome has blocked your popup. It's because popup-opening code is not in on-click handler.

Then you should open chrome's developer console and check "Console" tab for errors.

Also you should specify your domain name and port where your page is located in Google Developer Console like this: Google developer console - javascript origins

I was able to login into google and receive successful callback using your code but only after removing "immediate: true" option. I dont know why but i was getting "immediate_failed" error.

Ustim.S
  • 86
  • 2
  • Thanks. This was helpfull. In addition it worked only when I ran the html from a webserver (url start with http) and not directly through the file system. – GyRo Nov 09 '14 at 14:46