Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

343
Vistas
get my google drive files List with machine to machine authentication using javascript (insufficientFilePermissions)

i'm trying to get list of files (images) from google drive :

  1. i create google project (google console)
  2. i activate google drive api on my project
  3. i create api key and client id

i'm using javascript to handle my request:

const API_KEY = '...';
const ID_CLIENT = '...';
const scopes = [
    'https://www.googleapis.com/auth/drive',
    'https://www.googleapis.com/auth/drive.file',
    'https://www.googleapis.com/auth/drive.readonly',
    'https://www.googleapis.com/auth/drive.activity',
    'https://www.googleapis.com/auth/drive.activity.readonly',
    'https://www.googleapis.com/auth/drive.metadata',
    'https://www.googleapis.com/auth/drive.metadata.readonly',
    'https://www.googleapis.com/auth/drive.scripts',
    'Google_Service_Drive::DRIVE'
];

const googleDriveConf = {
    'apiKey': API_KEY,
    'clientId': ID_CLIENT,
    'scope': scopes[1],
    'plugin_name': 'Client Web deca'
};

function start() {
    // Initialize the JavaScript client library and auth.
    gapi.client.init(googleDriveConf)
        .then(function () {
            // Initialize and make the API request.
            const req = gapi.client.request({
                'path': `https://content.googleapis.com/drive/v3/files`,
                'method': 'GET',
                'params': {
                    'q': 'mimeType = "image/jpeg"',
                }
            })
            console.log(req)
            return req;
        }, function (reason) {
            console.log('auth: ', reason)
        })
        .then(function (response) {
            console.log(response.result);
        }, function (reason) {
            console.log('fetch files: ', reason) //error source
        });
}

gapi.load('client', start);

error response:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "insufficientFilePermissions",
    "message": "The user does not have sufficient permissions for this file."
   }
 ],
 "code": 403,
 "message": "The user does not have sufficient permissions for this file."
 }
}

i tried to fixe it without any success

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You may want to consult the JavaScript quick start

async function listFiles() {
    let response;
    try {
      response = await gapi.client.drive.files.list({
        'pageSize': 10,
        'fields': 'files(id, name)',
        'q': 'mimeType = "image/jpeg"',
      });
    } catch (err) {
      document.getElementById('content').innerText = err.message;
      return;
    }
    const files = response.result.files;
    if (!files || files.length == 0) {
      document.getElementById('content').innerText = 'No files found.';
      return;
    }
    // Flatten to string to display
    const output = files.reduce(
        (str, file) => `${str}${file.name} (${file.id}\n`,
        'Files:\n');
    document.getElementById('content').innerText = output;
  }

The error message you are getting does not make any sence to me. When looking at your code "The user does not have sufficient permissions for this file." is an error you would be getting if you were for example doing a file.get.

File.list would not return this error.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda