Jasper Bloo
Jasper Bloo

Reputation: 3

Gmail api - browser quickstart error: bad request

I followed Google gmail api browser quickstart step by step, but when I try to open index.html I get the following error:

{
  "error": {
    "errors": [
      {
        "domain": "usageLimits",
        "reason": "keyInvalid",
        "message": "Bad Request"
      }
    ],
    "code": 400,
    "message": "Bad Request"
  }
}

=(

Upvotes: 0

Views: 281

Answers (2)

user2585716
user2585716

Reputation:

In my case, I realize API_KEY is not the secret key from OAuth Credential process. So, I suppose you need to generate an API_KEY after generate a CLIENT_ID.

Upvotes: 1

Mr.Rebot
Mr.Rebot

Reputation: 6791

If you are not planning to use the API Key, kindly remove it in the request:

  function initClient() {
    gapi.client.init({
      apiKey: API_KEY, ///this one, since you didn't provide any value it will return an error.
      clientId: CLIENT_ID,
      discoveryDocs: DISCOVERY_DOCS,
      scope: SCOPES
    }).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());
      authorizeButton.onclick = handleAuthClick;
      signoutButton.onclick = handleSignoutClick;
    }, function(error) {
      appendPre(JSON.stringify(error, null, 2));
    });
  }

That should eliminate the issue you are encountering. My suggestion would be provide a valid API key from the console or remove it from the request (not sure how it will behave since in the quickstart they require both client ID and API key).

Upvotes: 0

Related Questions