Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught (in promise) TypeError: Cannot read property 'Zi' of undefined at handleSheetsAuth (sheets.oauth.js:58) - Google Sheets API #61

Closed
CPMikeAmato opened this issue Apr 17, 2020 · 0 comments

Comments

@CPMikeAmato
Copy link

CPMikeAmato commented Apr 17, 2020

Expected Behavior

We've had a Browser-based web application live and in production for about 8 months now and all the sudden without any code changes, new versions built/deployed, etc, our connection to Google Sheets seems to have broken.

Some context of the app: a table displaying many rows of various types of String data, nothing crazy here. We are using DataTables to display this data in a "pretty" way and have an "export to google sheet" button for users to export and edit this data locally, etc.

Error message we're seeing in the console:

Uncaught (in promise) TypeError: Cannot read property 'Zi' of undefined at handleSheetsAuth (sheets.oauth.js:58)

Below is the function inside sheets.oauth.js that is causing the error, line 58 is the line:
"if(!signInStatus || !gapi.auth2.getAuthInstance().currentUser.Ab.Zi.scope.toString().includes(SCOPES)) {"

`
async function handleSheetsAuth(headerData, bodyData, pageName) {
let signInStatus = await gapi.auth2.getAuthInstance().isSignedIn.get();
if(!signInStatus || !gapi.auth2.getAuthInstance().currentUser.Ab.Zi.scope.toString().includes(SCOPES)) {
let signedIn = await gapi.auth2.getAuthInstance().signIn();
}

let formattedDate = new Date().toLocaleString();
let spreadsheetBody = {
    "properties": {
        "title": "lorem ipsum - "+pageName+" Export - "+formattedDate
    }
};
let request = gapi.client.sheets.spreadsheets.create(spreadsheetBody);
request.then(function(response) {
    //console.log(response.result); // response.result.spreadsheetUrl // response.result.spreadsheetId
    let dataRequest = gapi.client.sheets.spreadsheets.values.batchUpdate({
        "spreadsheetId": response.result.spreadsheetId,
        "valueInputOption": "USER_ENTERED",
        "data": [{
            "range": "Sheet1!A1:AE1",
            "majorDimension": "ROWS",
            "values": [headerData]
        },
        {
            "range": "Sheet1!A2:AE20000",
            "majorDimension": "ROWS",
            "values": bodyData
        }]
    });
    dataRequest.then(function(dataResponse) {
        window.open(response.result.spreadsheetUrl, "_blank");
        return "success";
    }, function(dataReason) {
        return console.log('error: ' + dataReason.result.error.message);
    });
}, function(reason) {
    return console.log('error: ' + reason.result.error.message);
});

}
`

Thanks all,
Mike

@sqrrrl sqrrrl closed this as completed Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants