尝试使用/upload端点解决将文件上传到 Google Drive 的问题时遇到了一些麻烦。Malformed multipart body.即使当我尝试将简单的纯文本作为文件上传时,我仍然会收到错误消息。
以下 .net c# 代码用于创建请求:
string fileName = "test.txt";
string fileContent = "The quick brown fox jumps over the lazy dog";
var fileStream = GenerateStreamFromString(fileContent); // simple text string to Stream conversion
var streamContent = new StreamContent(fileStream);
streamContent.Headers.ContentType = new MediaTypeHeaderValue("text/plain");
var multiPartFormDataContent = new MultipartFormDataContent("not_so_random_boundary");
// rfc2387 headers with boundary
multiPartFormDataContent.Headers.Remove("Content-Type");
multiPartFormDataContent.Headers.TryAddWithoutValidation("Content-Type", "multipart/related; boundary=" + "not_so_random_boundary");
// metadata part
multiPartFormDataContent.Add(new StringContent("{\"name\":\"" + fileName + "\",\"mimeType\":\"text/plain\",\"parents\":[\"" + folder.id + "\"]}", Encoding.UTF8, "application/json")); …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 API 和 Python 创建一个 Google Docs 文件。
我遵循了他们的 API 指南和参考页面上的每条说明。
包括创建快速入门脚本
from __future__ import print_function
import pickle
import os.path
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request
# If modifying these scopes, delete the file token.pickle.
SCOPES = ['https://www.googleapis.com/auth/drive.metadata.readonly']
def main():
SCOPES = ['https://www.googleapis.com/auth/drive.file']
"""Shows basic usage of the Drive v3 API.
Prints the names and ids of the first 10 files the user has access to.
"""
creds = None
# The file token.pickle …Run Code Online (Sandbox Code Playgroud) 是否可以在 Google 共享云端硬盘中获取文件?PyDrive 能够迭代 MyDrive 中的文件,但不能迭代共享驱动器中的文件。这些文件位于多个文件夹中:
Department -> PDF -> MONTH YEAR -> DATE -> DAILY REPORT.pdf
尝试了代码,但都返回“查看文件夹级别”:
# #Make GoogleDrive instance with Authenticated GoogleAuth instance
# drive = GoogleDrive(gauth)
f = drive.ListFile({"q": "mimeType='application/vnd.google-apps.folder' and trashed=false}).GetList()
for folder in f:
print(folder['title'], folder['id'])
Run Code Online (Sandbox Code Playgroud)
查看文件级别:
# # Auto-iterate through all files that matches this query
# file_list = drive.ListFile({'q': "'{}' in parents and trashed=false".format(folder_id)}).GetList()
# # print(file_list)
# for file1 in file_list:
# print('title: %s, id: %s' % (file1['title'], file1['id']))
Run Code Online (Sandbox Code Playgroud) 我正在尝试制作一个包含 Shopify 订单和图片链接的表格。但异步循环有问题。每次我运行代码时,控制台中的顺序都会以错误的顺序出现,例如 998、996、1000... 应该是 1000、999、998...\n我尝试在不同的位置添加 async 关键字,并包装一个settimeout 函数中的函数等等,但没有运气。\n如何使订单列表按正确的顺序?\n提前谢谢您。
\n\nconst\xc2\xa0{google}\xc2\xa0=\xc2\xa0require(\'googleapis\');\r\nconst\xc2\xa0keys\xc2\xa0=\xc2\xa0require(\'./keys.json\');\r\nconst Shopify = require(\'shopify-api-node\');\r\nconst\xc2\xa0client\xc2\xa0=\xc2\xa0new\xc2\xa0google.auth.JWT(\r\n keys.client_email,\r\n null,\r\n keys.private_key,\r\n [\'https://www.googleapis.com/auth/spreadsheets\',\r\n \'https://www.googleapis.com/auth/drive.metadata.readonly\']\r\n);\r\nconst shopify = new Shopify({\r\n shopName: \'name.myshopify.com\',\r\n apiKey: \'key\',\r\n password: \'pas\'\r\n});\r\nconst\xc2\xa0sheets\xc2\xa0=\xc2\xa0google.sheets({version:\xc2\xa0\'v4\',\xc2\xa0auth:\xc2\xa0client});\r\nconst\xc2\xa0drive\xc2\xa0=\xc2\xa0google.drive({version:\xc2\xa0\'v3\',\xc2\xa0auth:\xc2\xa0client});\r\n\r\nfunction getLink(){\r\n client.authorize(()=> gsrun());\r\n}\r\n\r\nasync function runDrive(ord, sku){\r\n const resDrive = await drive.files.list({\r\n pageSize:\xc2\xa01,\r\n q: `name contains "sku"`,\r\n spaces:\xc2\xa0\'drive\',\r\n });\r\n const\xc2\xa0files\xc2\xa0=\xc2\xa0resDrive.data.files;\r\n let link;\r\n if\xc2\xa0(files.length)\xc2\xa0{\r\n link = `https://drive.google.com/file/d/${files[0].id}/view`;\r\n } else\xc2\xa0{\r\n // console.log(\'No\xc2\xa0files\xc2\xa0found.\');\r\n link = \'No\xc2\xa0files\xc2\xa0found.\';\r\n }\r\n console.log([ord, sku, link])\r\n}\r\n\r\nasync\xc2\xa0function\xc2\xa0gsrun(){\r\n // Shopify - Get orders list\r\n let orders = await shopify.order.list({ limit: 7 …Run Code Online (Sandbox Code Playgroud)javascript google-api node.js google-drive-api shopify-api-node
我正在尝试使用服务帐户使用域范围委派来进行 Google Drive API 调用。我可以让身份验证工作,但不能让驱动器 api 调用工作。错误:在驱动器中创建文件时找不到文件
此外,在域范围委派之前,我通过与服务帐户共享驱动器文件夹来使其工作。但现在我希望它能够在不共享的情况下工作。
我想我需要在某个地方做一些 setServiceAccount 的事情。不确定那会发生在哪里。
const {google} = require('googleapis');
const auth = new google.auth.JWT(
client_email, null,
privateKey, ['https://www.googleapis.com/auth/drive']
);
const drive = google.drive({version: "v3", auth});
//drive.files.create({});
Run Code Online (Sandbox Code Playgroud) 我创建了一个脚本,其中 Google Sheet 被转换为 PDF 并通过电子邮件发送(通过 Gmail API)。
请找到以下用于将工作表转换为 PDF 的语法
var blob=DriveApp.getFileById(<<Google Sheet ID>>).getAs('application/pdf');
Run Code Online (Sandbox Code Playgroud)
可以做什么来找出这里斑点的大小?
javascript blob google-sheets google-apps-script google-drive-api
我正在尝试创建一个简单的网络应用程序,自动将我的数据库和媒体备份上传到指定的谷歌驱动器。我按照官方文档创建了一个服务帐户凭据,赋予其所有者角色,并从 Google 云平台提取了密钥(json 文件)。我在我的帐户上启用了 Google Drive API 并编写了此代码,但credentials.valid 返回 False,并且我的文件不会上传到我的驱动器。
from google.oauth2 import service_account
import googleapiclient as google
from googleapiclient.http import MediaFileUpload, HttpRequest
from googleapiclient.discovery import build
SCOPES = ['https://www.googleapis.com/auth/drive']
credentials = service_account.Credentials.from_service_account_file('./service-credentials.json', scopes=SCOPES)
print(credentials.valid)
service = build('drive', 'v3', credentials=credentials)
file_metadata = {'name' : 'python.png'}
media = MediaFileUpload('./python.png', mimetype='image/png')
file_up = service.files().create(body=file_metadata, media_body=media, fields='id').execute()
file_back = service.files().get(fileId=file_up['id']).execute()
print(file_back.get('WebContentLink'))
Run Code Online (Sandbox Code Playgroud) python google-api google-drive-api google-oauth google-api-python-client
我已创建一个服务帐户,并让该帐户 (XXXX@XXXX.iam.gserviceaccount.com) 成为共享云端硬盘中的管理员。
我可以通过运行检索共享文件夹 IDservice.drives().list(pageSize=10).execute()
但如果我跑:
folder_id = '0ACNaJE1nx6YwXXXXXXX' # Same folder ID as above
query = "'%s' in parents" % folder_id
response = service.files().list(q=query, spaces='drive', fields='files(id, name, parents)').execute()
Run Code Online (Sandbox Code Playgroud)
{'files': []}即使共享文件夹包含一些文件,它也会返回。我究竟做错了什么?
我想将所有文件和文件夹权限重置为“受限”。在整个驱动器上。
谷歌驱动器上的权限不会级联,因此从父文件夹中删除它们不会在子文件夹和文件中删除它们。我有大量的文件和文件夹。
我发现带有脚本的过时帖子,但“Uiapp”功能已被弃用(评论中有人说它可以删除一些文件,所以不是我真正想要的)
这是类似内容的过时帖子(不再工作): https: //webapps.stackexchange.com/questions/37592/how-do-i-reset-permissions-for-google-drive-documents-in-all-子文件夹
我对编写任何类型的脚本都是陌生的,并且正在尝试编写Google Apps脚本来搜索文件夹中的特定字符串,如果找到,则将文件夹移动到另一个文件夹。
我可以复制一个文件夹,但不能移动它,因为复制的文件夹具有与原始文件夹相同的ID,删除一个文件夹会删除另一个文件夹。据我所知,我可以通过从文件夹中删除合适的孩子来实现这一点。我已经在API资源管理器中进行了尝试,它确实达到了我的期望。
问题是我一生都无法解决如何实现script.google.com的Google Drive SDK页面中给出的示例。如果我粘贴示例代码,则会在后面得到一个缺少的名称。操作员错误。没有一个脚本命令允许我删除一个孩子。
这可能是一个简单的问题,是由于我试图通过执行此项目来学习一些JavaScript而引起的,但是对于在Google Script中实现移动功能的任何帮助或建议,我将不胜感激。
具体的问题是:如何实现移动文件夹脚本?这是我正在尝试的方法,但是它同时删除了两个文件夹:
while (contents.hasNext()) {
folder = contents.next();
name = folder.getName();
if (name.search("XYZ") != -1) {
moveFolder = folder;
targetFolder.addFolder(moveFolder) moveFolder.setName('DEL_' +
moveFolder.getName());
removeFolder(moveFolder);
}
}
Run Code Online (Sandbox Code Playgroud) 如何将Windows上的同步目录切换为"Google云端硬盘"以外的其他目录?
即使我在Windows上,我也住在命令行中,在目录中嵌入空格是一件痛苦的事.
google-drive-api ×11
google-api ×3
python ×3
google-oauth ×2
javascript ×2
node.js ×2
python-3.x ×2
blob ×1
c# ×1
pydrive ×1