Home > database >  The call getOAuthToken returns null value - what am I missing?
The call getOAuthToken returns null value - what am I missing?

Time:04-11

I need to use a file picker in Apps Script, and I've tried the sample code from the Google Documentation but its not working - the ScriptApp.getOAuthToken() call is returning null.

I've followed all the instructions to change to a Standard Cloud Project and enabled the Google Picker API, but its just not happy.

CodePudding user response:

So it turns it was actually the call DriveApp.getRootFolder() that was failing in the function provided in the sample code:

function getOAuthToken() {
    try {
        DriveApp.getRootFolder();
        return ScriptApp.getOAuthToken();
    } catch (e) {
        // TODO (Developer) - Handle exception
        Logger.log('Failed with error: %s', e.error);
    }
}

While the sample code works correctly without this call, I discovered the reason for the error was that I needed to enable the Google Drive API after switching to a Standard Cloud Project (required to run the Google Picker API).

  • Related