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";
var API_KEY = "AIzaN0tRe4lLyAn4pIk5y";
// Array of API discovery doc URLs for APIs used by the quickstart
var DISCOVERY_DOCS = ["/$discovery/rest?version=v4"];
// Authorization scopes required by the API; multiple scopes can be
// included, separated by spaces.
var SCOPES = ".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.
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.";
var API_KEY = "AIzaN0tRe4lLyAn4pIk5y";
// Array of API discovery doc URLs for APIs used by the quickstart
var DISCOVERY_DOCS = ["https://sheets.googleapis./$discovery/rest?version=v4"];
// Authorization scopes required by the API; multiple scopes can be
// included, separated by spaces.
var SCOPES = "https://www.googleapis./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.
Share Improve this question edited May 2, 2019 at 5:56 icedwater asked May 7, 2017 at 11:19 icedwatericedwater 4,8873 gold badges38 silver badges53 bronze badges 5-
Update the value of
var CLIENT_ID
. To get the credentials, follow the Step 1 - d to i in this JavaScript Quickstart. You can not callinit()
on its own because it is dependent on this functionhandleClientLoad()
which loads the auth2 library and API client library. – Mr.Rebot Commented May 7, 2017 at 17:24 -
I was using a valid
CLIENT_ID
, I just wasn't going to paste it here. But thanks for the note thatinit()
will fail on its own. – icedwater Commented May 10, 2017 at 2:06 -
Anything new about this? I'm having the same problem with the Calendar API. I have my API Key and the web client ID. They are both correct. Also I have
discoveryDocs
in the init call :S – Osakr Commented Jan 23, 2019 at 12:44 - Hmm, this isn't solved despite having simmered for 2 years. Am I missing something here? – icedwater Commented May 1, 2019 at 8:43
- 1 I have the same problem with google calendar API – brian bentancourt Commented Sep 9, 2021 at 19:29
1 Answer
Reset to default 6I also faced the same problem.
In the initClient
function I replaced gapi.client.init
to gapi.auth2.init
and it worked.