我正在根据 Google Team Drive 文件的内容实现一个基于树的查看器;为此,我遵循此处给出的建议:How do I search sub-folders and sub-sub-folders in Google Drive? ,即执行 2 个 API 调用 - 一个用于获取所有文件夹,另一个用于获取这些文件夹的直接子级的所有文件。
但是,我注意到获取所有文件夹的调用并未返回所有文件夹:
res = service.files().list(
corpora='teamDrive',
pageSize=1000,
supportsTeamDrives=True,
includeTeamDriveItems=True,
teamDriveId=TEAM_DRIVE_ID,
fields='files(id,parents,name,mimeType)',
q="mimeType='application/vnd.google-apps.folder' and trashed=false"
).execute()
len(res['files'])
# 460
Run Code Online (Sandbox Code Playgroud)
在这里,文件不应该超过pageSize,但我肯定从这个结果中丢失了大量文件夹,例如 id 为 的特定文件夹specified_id:
len([x for x in res['files'] if x['id'] == specified_id])
# 0
Run Code Online (Sandbox Code Playgroud)
我不认为这是权限问题,因为我可以正常获取此文件:
specific_file = service.files().get(
fileId=specified_id,
supportsTeamDrives=True,
).execute()
specific_file
{'id': '...',
'kind': 'drive#file',
'mimeType': 'application/vnd.google-apps.folder',
'name': '...',
'teamDriveId': '...'}
Run Code Online (Sandbox Code Playgroud)
为了实现在一个 API 请求中获取 Google(团队)云端硬盘中的所有文件夹的目标,有关尝试其他事情的任何其他提示将不胜感激。
我正在尝试使用 PyDrive 以编程方式列出并下载存储在我可以在浏览器中访问的团队驱动器上的文件。当我这样做时:
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
gauth = GoogleAuth()
drive = GoogleDrive(gauth)
file_list = drive.ListFile(
{
'q': "'root' in parents and trashed=false",
'corpora': "teamDrive",
'teamDriveId': <team drive ID>,
'includeTeamDriveItems': "true",
'supportsTeamDrives': "true"
}
).GetList()
for file1 in file_list:
print('title: %s, id: %s' % (file1['title'], file1['id']))
Run Code Online (Sandbox Code Playgroud)
我只得到我个人驱动器上的文件列表,而不是团队驱动器。我究竟做错了什么?
注意1:我<team drive ID>通过在浏览器中打开团队驱动器(根文件夹)并复制“ https://drive.google.com/drive/folders/ ”之后的所有内容来获得
注2:浏览器弹出drive.ListFile并给出Authentication successful.
我想知道如何使用 Google 的 Drive API 在团队驱动器中创建文件。
这是 google Drive api 文档中文件和 teamdrive 的参考。
https://developers.google.com/drive/api/v3/reference/files
https://developers.google.com/drive/api/v3/reference/files/create
https://developers.google.com/drive/api/v3/enable-shareddrives
const resource = {
name: fileName,
supportsAllDrives: true,
driveId: TEAMDRIVE_ID,
mimeType: 'application/vnd.google-apps.spreadsheet'
};
drive.files.create(
{
resource,
fields: 'id, name, webViewLink'
},
(err, file) => {
if (err) {
return({ msg: 'Failed Creating the file', err });
} else {
return file.data;
}
}
);
Run Code Online (Sandbox Code Playgroud)
该代码能够创建该文件,但它不会出现在团队驱动器中。它出现在我的个人驱动器中。我能够读取团队驱动器中的文件。创建文件对我来说一直是个问题......
我正在创建一项服务来查看 Google 云端硬盘上的一些共享云端硬盘文件夹。我使用服务帐户进行身份验证,因为这是在服务器上运行的服务。这是我的代码片段:
const { google } = require("googleapis");
const auth = new google.auth.GoogleAuth({
keyFile: "./credentials.json",
scopes: ["https://www.googleapis.com/auth/drive"],
});
const drive = google.drive({ version: "v3", auth });
drive.drives
.list({ q: "name = Clients", useDomainAdminAccess: true })
.then((files) => {
console.log(files);
})
.catch((err) => {
console.log(err);
});
Run Code Online (Sandbox Code Playgroud)
如果我将list方法参数留空,我会收到状态代码 200 的响应以及预期的空驱动器列表(因为服务帐户不拥有任何共享驱动器)。一旦我添加 useuseDomainAdminAccess: true参数,我就会收到如下错误响应:
GaxiosError: Invalid Value
at Gaxios._request (/Users/bteres/Projects/fw-docs/node_modules/gaxios/build/src/gaxios.js:85:23)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async JWT.requestAsync (/Users/bteres/Projects/fw-docs/node_modules/google-auth-library/build/src/auth/oauth2client.js:342:22) {
response: {
config: {
url: 'https://www.googleapis.com/drive/v3/drives?q=name%20%3D%20Clients&useDomainAdminAccess=true',
method: 'GET',
userAgentDirectives: [Array],
paramsSerializer: …Run Code Online (Sandbox Code Playgroud) 谷歌应用程序脚本新手在这里。我发现这段代码可以帮助使用 Google Sheet 中的输入在我的个人 Google Drive 中创建文件夹(来源:Youtube 上的 Google Sheet Community)。但是,当我尝试在共享的 Google 驱动器中重新创建此应用程序时,它无法运行并继续在我的个人驱动器中创建文件夹。我可以对代码进行任何更改,使其在共享驱动器环境而不是我自己的环境中工作吗?
多谢!
var ui = SpreadsheetApp.getUi();
// Or DocumentApp or FormApp.
ui.createMenu('GDrive')
.addItem('Create new Folders', 'crtGdriveFolder')
.addToUi(); }
function crtGdriveFolder() {
var sheet = SpreadsheetApp.getActiveSheet();
var startRow = 2; // First row of data to process
var numRows = sheet.getLastRow(); // Number of rows to process
var maxRows = Math.min(numRows,20); //Limit the number of rows to prevent enormous number of folder creations
var folderid = sheet.getRange("C2").getValue();
var root …Run Code Online (Sandbox Code Playgroud) google-apps-script google-drive-api google-drive-shared-drive
希望你能帮我解决这个问题。很困惑为什么这会给我带来问题。
按照快速入门指南,我能够将文件打印到控制台。酷,我看到第二个参数files.list是传入的回调res/error
节点:v8.3.0 npm:v5.3.0
const { google } = require('googleapis');
const express = require('express');
const fs = require('fs');
const keys = require('./credentials.json');
const app = express();
const drive = google.drive('v3');
const scopes = [
"https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/drive.file",
"https://www.googleapis.com/auth/drive.metadata.readonly"
];
// Create an oAuth2 client to authorize the API call
const client = new google.auth.OAuth2(
keys.web.client_id,
keys.web.client_secret,
keys.web.redirect_uris[0]
);
// Generate the url that will be used for authorization
this.authorizeUrl = client.generateAuthUrl({
access_type: 'offline',
scope: scopes
});
// Open …Run Code Online (Sandbox Code Playgroud) 在Google API 资源管理器上,我尝试在drive.permissions.create 中提供正确的fileId。我将supportsTeamDrives 设置为true,请求主体的角色为:读者,类型为:任何人。这只是给了我错误:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalidLinkVisibility",
"message": "Bad Request. User message: \"\""
}
],
"code": 400,
"message": "Bad Request. User message: \"\""
}
}
Run Code Online (Sandbox Code Playgroud)
我的 PHP 代码也是如此。这是我能得到的最接近的,对我来说看起来很正确:
...
$userPermission = new Google_Service_Drive_Permission( array(
'type' => 'anyone',
'role' => 'reader',
));
$service->permissions->create( $imageId, $userPermission, array(
'supportsTeamDrives' => true,
));
...
Run Code Online (Sandbox Code Playgroud)
我在错误中找不到任何内容:
无效链接可见性
我需要做的是暂时将文件夹中 20-50 个文件的权限设置为“公共”(即任何知道该链接的人都可以看到它),因为我正在发送 webContentLink(或 webViewLink,我还没有弄清楚我还需要使用哪一个)到另一个 API 来上传图像。完成此操作后,我想删除公共访问权限。一种选择是将文件夹的权限(具有递归公共访问权限)设置为公共访问。我只是不知道如何在 PHP 中更改(或者更确切地说添加)Google Drive API 中文件的权限。
另一种方法是,如果有某种方法可以通过包含令牌的 URL 获取图像,例如
$source = …Run Code Online (Sandbox Code Playgroud) 这可能是一个非常简单的问题,但我似乎无法弄清楚。最近,我们将一个项目从Google云端硬盘上的共享文件夹移到了团队云端硬盘。我曾经使用以下代码直接从R访问电子表格:
library(googlesheets)
mydir <- gs_ls() #authenticate to google list sheets
mydir$sheet_title
mygs <- gs_title(x = "FileName", verbose = F) #read file
mygs <- gs_read(ss = mygs, ws = "SheetName", skip=1) # get specific worksheet
Run Code Online (Sandbox Code Playgroud)
但是,既然我们移动了该项目,该项目将无法再使用,因为googlesheets软件包仅适用于我的Google云端硬盘目录。我找到了一个用于访问我的Team Drive(googledrive)的程序包,并且设法在目录中找到了该文件,但是似乎无法弄清楚如何阅读我的特定工作表:
library(googledrive)
td <- team_drive_find()
myfile <- drive_find(team_drive = as_id(td$id[td$name=="TDriveName"]),
pattern = "FileName")
myfile <- drive_get(id = as_id(myfile$id), verbose = TRUE)
Run Code Online (Sandbox Code Playgroud)
这使我对电子表格的元数据有所了解,但没有像gs_title()这样的实际电子表格。必须具有执行此功能的功能吗?
我想将文件夹复制到 Google 云端硬盘内的主文件夹中。我的主要问题是当一列不为空而另一列为空白时创建一个函数。创建新文件夹后,必须将文件夹 URL 粘贴到其中一列中。
这是我到目前为止所拥有的:
function addData(){
var activeSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Data");
var lr = activeSheet.getLastRow();
var lc = activeSheet.getLastColumn();
var sourceData = sourceSheet.getRange(1, 1, lr, lc).getValues();
for (row in sourceData) {
if (sourceData[row][0] !== "" && sourceData[row][19] !== "") {
var rowNum = parseInt(row);
//code will go here for Folder copying and renaming and getting the new folder url
activeSheet.getRange(rowNum+1,lc).setValue("Completed"); //we will eventually change Completed with the new Folder URL
}
}
}
Run Code Online (Sandbox Code Playgroud) javascript directory-structure google-apps-script google-drive-shared-drive
现在我想在网站(http://pubchemqc.riken.jp/)上下载数据集,它位于Google Drive中,文件大小为2TB。网站推荐使用rclone下载文件,但没有说如何使用。 如图所示
node.js ×2
download ×1
javascript ×1
permissions ×1
php ×1
pydrive ×1
python ×1
r ×1
rclone ×1