Google Forms API: Cannot find module '/my/path/to/credentials.json'

57 views Asked by At

I want to get data from Google Forms API with the following TypeScript code, copied from the document:

const path = require('path');
const google = require('@googleapis/forms');
const {authenticate} = require('@google-cloud/local-auth');

const formID = 'formID';

async function runSample() {
    const auth = await authenticate({
        keyfilePath: path.join(__dirname, 'credentials.json'),
        scopes: 'https://www.googleapis.com/auth/forms.responses.readonly',
    });
    const forms = google.forms({
        version: 'v1',
        auth: auth,
    });
    const res = await forms.forms.responses.list({
        formId: formID,
    });
    console.log(res.data);
    return res.data;
}
runSample(); 

I also have the file credentials.json in the needed directory with the following structure:

{"web":
   {"client_id":"client_id",
    "project_id":"project_id",
    "auth_uri":"auth_uri",
    "token_uri":"token_uri",
    "auth_provider_x509_cert_url":"auth_provider_x509_cert_url",
    "client_secret":"client_secret"
    }
}

But there is still an error say "Cannot find module '/my/path/to/credentials.json'", please help me fix this.

Thanks everyone.

0

There are 0 answers