Google-api-javascript-client: not work

Created on 27 May 2017  Â·  14Comments  Â·  Source: google/google-api-javascript-client

"Not a valid origin for the client: http://xxxx.beget.tech has not been whitelisted for client ID 9999-qweerty.apps.googleusercontent.com. Please go to https://console.developers.google.com/ and whitelist this origin for your project's client ID."

how i can that?

Most helpful comment

This solve it for me. Long press on reload button

screen shot 2019-03-01 at 12 41 48 pm

All 14 comments

Please go to https://console.developers.google.com/apis/credentials, click on the 'edit' button of your Client ID, and add your site to the origin whitelist.

If you are on staging delete the account key and recreated it again.

I have created origins and call back right but still not working ??

@mateegojra Please provide more information (snippet of code, origin tested, etc.)

Facing the same problem.

I was testing it using this piece of code.

<html><head><title>Google APIs - Sample JS Page</title></head>
<body>

<script>

  /***** START BOILERPLATE CODE: Load client library, authorize user. *****/

  // Global variables for GoogleAuth object, auth status.
  var GoogleAuth;

  /**
   * Load the API's client and auth2 modules.
   * Call the initClient function after the modules load.
   */
  function handleClientLoad() {
    gapi.load('client:auth2', initClient);
  }

  function initClient() {
    // Initialize the gapi.client object, which app uses to make API requests.
    // Get API key and client ID from API Console.
    // 'scope' field specifies space-delimited list of access scopes

    gapi.client.init({
        'clientId': 'REPLACE_ME',
        'discoveryDocs': ['https://www.googleapis.com/discovery/v1/apis/youtube/v3/rest'],
        'scope': 'https://www.googleapis.com/auth/youtube.force-ssl https://www.googleapis.com/auth/youtubepartner'
    }).then(function () {
      GoogleAuth = gapi.auth2.getAuthInstance();

      // Listen for sign-in state changes.
      GoogleAuth.isSignedIn.listen(updateSigninStatus);

      // Handle initial sign-in state. (Determine if user is already signed in.)
      setSigninStatus();

      // Call handleAuthClick function when user clicks on "Authorize" button.
      $('#execute-request-button').click(function() {
        handleAuthClick(event);
      }); 
    });
  }

  function handleAuthClick(event) {
    // Sign user in after click on auth button.
    GoogleAuth.signIn();
  }

  function setSigninStatus() {
    var user = GoogleAuth.currentUser.get();
    isAuthorized = user.hasGrantedScopes('https://www.googleapis.com/auth/youtube.force-ssl https://www.googleapis.com/auth/youtubepartner');
    // Toggle button text and displayed statement based on current auth status.
    if (isAuthorized) {
      defineRequest();
    }
  }

  function updateSigninStatus(isSignedIn) {
    setSigninStatus();
  }

  function createResource(properties) {
    var resource = {};
    var normalizedProps = properties;
    for (var p in properties) {
      var value = properties[p];
      if (p && p.substr(-2, 2) == '[]') {
        var adjustedName = p.replace('[]', '');
        if (value) {
          normalizedProps[adjustedName] = value.split(',');
        }
        delete normalizedProps[p];
      }
    }
    for (var p in normalizedProps) {
      // Leave properties that don't have values out of inserted resource.
      if (normalizedProps.hasOwnProperty(p) && normalizedProps[p]) {
        var propArray = p.split('.');
        var ref = resource;
        for (var pa = 0; pa < propArray.length; pa++) {
          var key = propArray[pa];
          if (pa == propArray.length - 1) {
            ref[key] = normalizedProps[p];
          } else {
            ref = ref[key] = ref[key] || {};
          }
        }
      };
    }
    return resource;
  }

  function removeEmptyParams(params) {
    for (var p in params) {
      if (!params[p] || params[p] == 'undefined') {
        delete params[p];
      }
    }
    return params;
  }

  function executeRequest(request) {
    request.execute(function(response) {
      console.log(response);
    });
  }

  function buildApiRequest(requestMethod, path, params, properties) {
    params = removeEmptyParams(params);
    var request;
    if (properties) {
      var resource = createResource(properties);
      request = gapi.client.request({
          'body': resource,
          'method': requestMethod,
          'path': path,
          'params': params
      });
    } else {
      request = gapi.client.request({
          'method': requestMethod,
          'path': path,
          'params': params
      });
    }
    executeRequest(request);
  }

  /***** END BOILERPLATE CODE *****/


  function defineRequest() {
    // See full sample for buildApiRequest() code, which is not 
// specific to a particular API or API method.

buildApiRequest('GET',
                '/youtube/v3/playlistItems',
                {'maxResults': '25',
                 'part': 'snippet,contentDetails',
                 'playlistId': 'PLBCF2DAC6FFB574DE'});

  }
</script>

<button id="execute-request-button">Authorize</button>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script async defer src="https://apis.google.com/js/api.js" 
        onload="this.onload=function(){};handleClientLoad()" 
        onreadystatechange="if (this.readyState === 'complete') this.onload()">
</script>
</body></html>

Thanks

On Sun, Feb 18, 2018 at 12:07 AM, Yashu Mittal notifications@github.com
wrote:

Facing the same problem.

I was testing it using this piece of code.

Google APIs - Sample JS Page

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/google/google-api-javascript-client/issues/301#issuecomment-366463980,
or mute the thread
https://github.com/notifications/unsubscribe-auth/Ab637dm08AIj2maqb5N4LPMdLsjBMrYCks5tVyNWgaJpZM4NoS7f
.

--

[image: --]

Matee Gojra
[image: https://]about.me/mateegojra
https://about.me/mateegojra?promo=email_sig&utm_source=email_sig&utm_medium=email_sig&utm_campaign=external_links

@mittalyashu @mateegojra could you try again after clearing your cache?

Did that, but still facing the same problem.

@mittalyashu did you check that the content of window.location.origin is in the authorized origins in the developers console, for the client ID used?

Clearing the cache solved the issue. What did not solve it was pressing "Clear site data" in Chrome which I find confusing.

Clearing the cache solved the issue. What did not solve it was pressing "Clear site data" in Chrome which I find confusing.

This actually solved the issue. Thanks sakalys

This solve it for me. Long press on reload button

screen shot 2019-03-01 at 12 41 48 pm

if you are testing locally, use http://localhost:8080 (or whatever port you are using) for both whitlisting at https://console.developers.google.com/apis/credentials and on your browser (not http://127.0.0.1:8080) .this worked for me

i have the same problem. and when i open https://console.developers.google.com/apis/credentials, there is nothing in there ! what should i do ?

Was this page helpful?
0 / 5 - 0 ratings