0

I spent a lot of days to find way to authentificate to google admin api with service account. Now I have new error message:

Error: native promise missing, set fetch.Promise to your favorite alternative

Here my code:

require('../global')
const fs = require('fs');
const {google} = require('googleapis');

const KEYFILE = global.service_account;
const SCOPES = global.scopes;

(async function run() {
    async function readPrivateKey() {
        const content = fs.readFileSync(KEYFILE);
        return JSON.parse(content.toString());
    }

    async function authenticate(key) {
        const jwtClient = new google.auth.JWT(
            key.client_email,
            null,
            key.private_key,
            SCOPES
        );
        await jwtClient.authorize();
        return jwtClient;
    }

    async function createEvent(auth) {
        let admin = google.admin({ version: 'directory_v1' });
        await admin.users.list({
            customer:'my_customer',
            maxResults: 500
        });
    }

    // MAIN
    try {
        const key = await readPrivateKey();
        console.log(key)
        const auth = await authenticate(key);
        await createEvent(auth);
    } catch (e) {
        console.log('Error: ' + e);
    }
})();

1 Answers1

0

This means you're using an older version of Node (< 6.0.0) that doesn't have Promise functionality and should upgrade to a newer version, otherwise you have to use a library like Bluebird to provide Promise functionality.

selfagency
  • 1,481
  • 1
  • 9
  • 12