我正在尝试使用 Google Drive API 的“浏览器”版本,它似乎主要遵循 Nodejs 语法。但除了浏览器的第一个 hello world 示例之外,似乎没有太多示例。
现在我正在尝试创建一个文件夹,然后在该文件夹内创建一个简单的 JSON 配置文件作为概念证明。然而,当我运行此代码时,我只在我的 Google 云端硬盘中得到一个标有“无标题”的空文件。
这是文件创建的片段,返回成功。
this.MEM.config = {
categories : {},
createdOn : Date.now()
}
let fileMetadata = {
name : 'config.json',
parents : [this.MEM.parent]
}
let media = {
mimeType : 'application/json',
body : JSON.stringify(this.MEM.config)
}
query = {
resource: fileMetadata,
media: media,
fields: 'id'
}
console.log(query);
try {
res = await gapi.client.drive.files.create(query);
} catch(err) {
throw err;
}
console.log(res);
结果似乎不会产生任何错误:
{
"result": {
"id": "1OI0ttFr11UH1__XAlSnyUil5hpp6mScB"
},
"body": "{\n \"id\": \"1OI0ttFr11UH1__XAlSnyUil5hpp6mScB\"\n}\n",
"headers": {
"cache-control": "no-cache, no-store, max-age=0, must-revalidate",
"content-encoding": "gzip",
"content-length": "67",
"content-type": "application/json; charset=UTF-8",
"date": "Thu, 29 Apr 2021 20:26:13 GMT",
"expires": "Mon, 01 Jan 1990 00:00:00 GMT",
"pragma": "no-cache",
"server": "GSE",
"vary": "Origin, X-Origin"
},
"status": 200,
"statusText": "OK"
}
除了在我用字符串化对象指定的文件夹中创建“config.json”文件之外,我只是在 Google Drive 的根目录中获得一个 Untitled 文件。