title: API key not valid error when trying to get profile data
body: <p>I'm trying to test Google login API. I want to retrieve some basic data after the client logs.</p>
  
  <p>I created a Google API Console project and client ID  (<a href="https://developers.google.com/identity/sign-in/web/devconsole-project" rel="nofollow noreferrer">https://developers.google.com/identity/sign-in/web/devconsole-project</a>)</p>
  
  <p>Here is google official code (<a href="https://developers.google.com/api-client-library/javascript/samples/samples#LoadinganAPIandMakingaRequest" rel="nofollow noreferrer">https://developers.google.com/api-client-library/javascript/samples/samples#LoadinganAPIandMakingaRequest</a>):</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;script type="text/javascript"&gt;
        function handleClientLoad() {
          // Loads the client library and the auth2 library together for efficiency.
          // Loading the auth2 library is optional here since `gapi.client.init` function will load
          // it if not already loaded. Loading it upfront can save one network request.
          gapi.load('client:auth2', initClient);
        }
  
        function initClient() {
          // Initialize the client with API key and People API, and initialize OAuth with an
          // OAuth 2.0 client ID and scopes (space delimited string) to request access.
          gapi.client.init({
              apiKey: '5v2RzP7-xyQGNjxrD5suoPL9',
              discoveryDocs: ["https://people.googleapis.com/$discovery/rest?version=v1"],
              clientId: '298062822261-e5c09q8191mkho0o7n3n3obiq2eq2p3f.apps.googleusercontent.com',
              scope: 'profile'
          }).then(function () {
            // Listen for sign-in state changes.
            gapi.auth2.getAuthInstance().isSignedIn.listen(updateSigninStatus);
  
            // Handle the initial sign-in state.
            updateSigninStatus(gapi.auth2.getAuthInstance().isSignedIn.get());
          });
        }
  
        function updateSigninStatus(isSignedIn) {
          // When signin status changes, this function is called.
          // If the signin status is changed to signedIn, we make an API call.
          if (isSignedIn) {
            makeApiCall();
          }
        }
  
        function handleSignInClick(event) {
          // Ideally the button should only show up after gapi.client.init finishes, so that this
          // handler won't be called before OAuth is initialized.
          gapi.auth2.getAuthInstance().signIn();
        }
  
        function handleSignOutClick(event) {
          gapi.auth2.getAuthInstance().signOut();
        }
  
        function makeApiCall() {
          // Make an API call to the People API, and print the user's given name.
          gapi.client.people.people.get({
            resourceName: 'people/me'
          }).then(function(response) {
            console.log('Hello, ' + response.result.names[0].givenName);
          }, function(reason) {
            console.log('Error: ' + reason.result.error.message);
          });
        }
      &lt;/script&gt;
      &lt;script async defer src="https://apis.google.com/js/api.js"
              onload="this.onload=function(){};handleClientLoad()"
              onreadystatechange="if (this.readyState === 'complete') this.onload()"&gt;
      &lt;/script&gt;
      &lt;button id="signin-button" onclick="handleSignInClick()"&gt;Sign In&lt;/button&gt;
      &lt;button id="signout-button" onclick="handleSignOutClick()"&gt;Sign Out&lt;/button&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>ClientId and apikey are from my google api.</p>
  
  <p>I receive error 400</p>
  
  <pre><code>{
    "error": {
      "code": 400,
      "message": "API key not valid. Please pass a valid API key.",
      "status": "INVALID_ARGUMENT",
      "details": [
        {
          "@type": "type.googleapis.com/google.rpc.Help",
          "links": [
            {
              "description": "Google developers console",
              "url": "https://console.developers.google.com"
            }
          ]
        }
      ]
    }
  }
  </code></pre>
  
  <p>I don't understand what's wrong whit my api key. I followed all the steps from google documentation.</p>