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?

1 Answer 1

0
+50

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.