Javascript commands won't execute as expected.

I'm trying to follow the sample example from google developer tutorial
using updated chrome (version 38.0)

But it looks like the gapi.auth functions never reached their callbacks

Here's some sample code that demonstrates this:

<!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 two optional "HandleAuthResult" warnings are displayed on the screen at all - it means this function is not called 'gapi.auth.authorize'

Anyone could use this library correctly?

+3


source to share


1 answer


First of all, you need to check if Chrome has blocked your popup. This is because the popup code is not in the handler.

Then you need to open the Chrome Developer Console and check the Console tab for errors.



Also you have to provide your domain name and port where your page is in google developer console, for example: Google developer console - javascript origins

I was able to go to Google and get a successful callback using your code, but only after removing the "immediate: true" option. I don't know why, but I was getting an "immediate_file" error.

0


source







All Articles