I have a function that calls an apps script that has been deployed as an executable script.
I setup oAuth with the correct necessary scopes in a react app and then I call my API request to get data from the app script.
const connectToDrive = async () => {
const authToken = await window.gapi.auth2
.getAuthInstance()
.currentUser.get()
.getAuthResponse().id_token;
console.log('token', authToken);
window.gapi.client.script.scripts
.run({
scriptId,
resource: {
function: 'setUpOrReadRoot',
},
})
.then(resp => console.log('result', resp.result))
.catch(err => console.log('err', err));
};
The error I get is 401 UNAUTHENTICATED.
{
"result": {
"error": {
"code": 401,
"message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED"
}
},
"body": "{\n \"error\": {\n \"code\": 401,\n \"message\": \"Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.\",\n \"status\": \"UNAUTHENTICATED\"\n }\n}\n",
"headers": {
"date": "Thu, 04 Apr 2019 06:50:59 GMT",
"content-encoding": "gzip",
"server": "ESF",
"content-type": "application/json; charset=UTF-8",
"vary": "Origin, X-Origin, Referer",
"cache-control": "private",
"content-length": "228"
},
"status": 401,
"statusText": null
}
I'm logging my access token out before I call the api so I know I am logged in and have an access token.
How do I explicitly attach the access token to the window.gapi.client.script.scripts.run()
request?