'The call getOAuthToken returns null value - what am I missing?

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.



Solution 1:[1]

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).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1