gpt4 book ai didi

node.js - 驱动服务API某些参数不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 01:53:06 27 4
gpt4 key购买 nike

标题说明了一切,fieldsq 由于某种原因不起作用。在我的云端硬盘中,我有一个名为“Imprensa”的文件夹,与 fatherId 对应,在该文件夹内我有更多文件夹,这些文件夹用作每个文件夹的类别(例如:新闻、文章、信息等)。该查询应该获取这些文件夹,这些文件夹的父级是“父亲”(Imprensa),但它会显示我的云端硬盘中包含的所有内容。我刚刚复制了 Google Drive APIs Rest docs for node 中的快速入门,所以基本上,代码是相同的。
驱动器 API v3
googleapis v26.0.1

var fs = require('fs');
var readline = require('readline');
var google = require('googleapis');
var googleAuth = require('google-auth-library');

// If modifying these scopes, delete your previously saved credentials
// at ~/.credentials/drive-nodejs-quickstart.json
var SCOPES = ['https://www.googleapis.com/auth/drive.metadata.readonly'];
var TOKEN_DIR = (process.env.HOME || process.env.HOMEPATH ||
process.env.USERPROFILE) + '/.credentials/';
var TOKEN_PATH = TOKEN_DIR + 'drive-nodejs-quickstart.json';

// Load client secrets from a local file.
fs.readFile('client_secret.json', function processClientSecrets(err, content) {
if (err) {
console.log('Error loading client secret file: ' + err);
return;
}
// Authorize a client with the loaded credentials, then call the
// Drive API.
authorize(JSON.parse(content), listFiles);
});

function authorize(credentials, callback) {
var clientSecret = credentials.installed.client_secret;
var clientId = credentials.installed.client_id;
var redirectUrl = credentials.installed.redirect_uris[0];
var auth = new googleAuth();
var oauth2Client = new auth.OAuth2(clientId, clientSecret, redirectUrl);

// Check if we have previously stored a token.
fs.readFile(TOKEN_PATH, function (err, token) {
if (err) {
getNewToken(oauth2Client, callback);
} else {
try {
oauth2Client.credentials = JSON.parse(token);
} catch (error) {
console.log('error: ', error);
}
callback(oauth2Client);
}
});
}

function getNewToken(oauth2Client, callback) {

var authUrl = oauth2Client.generateAuthUrl({
access_type: 'offline',
scope: SCOPES
});
console.log('Authorize this app by visiting this url: ', authUrl);
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('Enter the code from that page here: ', function (code) {
rl.close();
oauth2Client.getToken(code, function (err, token) {
if (err) {
console.log('Error while trying to retrieve access token', err);
return;
}
oauth2Client.credentials = token;
storeToken(token);
callback(oauth2Client);
});
});
}

function storeToken(token) {
try {
fs.mkdirSync(TOKEN_DIR);
} catch (err) {
if (err.code != 'EEXIST') {
throw err;
}
}
fs.writeFile(TOKEN_PATH, JSON.stringify(token));
console.log('Token stored to ' + TOKEN_PATH);
}

function listFiles(auth) {
var service = google.google.drive('v3');
const fatherId = '15buNwg19v6u9tY4AuJBjmy1q1ySdiRo4';

service.files.list({
auth: auth,
// 'orderBy': 'modifiedTime desc',
fields: 'nextPageToken, files(id, name)',
q: `'${fatherId}' in parents`
}, function (err, response) {
var folders = response.files;
console.log('folders: ', folders);
});
}

最佳答案

这个修改怎么样?

来自:

q: `parents in '${fatherId}'`

致:

q: `'${fatherId}' in parents`

注意:

  • 这假设您已经可以检索访问 token 。

引用:

如果这对您的情况没有用,我很抱歉。

编辑:

经查,该问题的原因是googleapis版本问题。当使用v26时,就会出现此问题。当 googleapis 降级到 v24 时,不会出现问题。

关于node.js - 驱动服务API某些参数不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48956196/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com