client_id and scope must both be provided to initialize OAuth

google-sheets-api, javascript

Solution

I also faced the same problem. In the `initClient` function I replaced `gapi.client.init` to `gapi.auth2.init` and it worked.

Problem

I'm working off Google Sheets API Javascript Quickstart and have run into an authentication issue with `gapi.client.init()`. Here is the code that's giving me issues: ``` // Client ID and API key from the Developer Console var CLIENT_ID = "50m3-cle3nt-1d.apps.googleusercontent.com"; var API_KEY = "AIzaN0tRe4lLyAn4pIk5y"; // Array of API discovery doc URLs for APIs used by the quickstart var DISCOVERY_DOCS = ["https://sheets.googleapis.com/$discovery/rest?version=v4"]; // Authorization scopes required by the API; multiple scopes can be // included, separated by spaces. var SCOPES = "https://www.googleapis.com/auth/spreadsheets.readonly"; function initClient() { gapi.client.init({ apiKey: API_KEY, discoveryDocs: DISCOVERY_DOCS, clientId: CLIENT_ID, scope: SCOPES }).then(function() { // doesn't matter. }) } ``` I can't get the `init()` call to work, and I get the error as in the question title even if I try to call `init()` on its own inside the console: ``` > k = gapi.client.init({ ... }) client_id and scope must both be provided to initialize OAuth ``` What am I missing in the call to `init()`? Any tips would be appreciated.

Original source