我正在尝试将文件上传到 Google 云端硬盘。运行该程序后,我得到状态 200,但在云端硬盘中找不到该文件。fileMetadata我在该键下的变量中输入了文件夹 ID parents。
这是我的代码:
const { google } = require('googleapis');
const credentials = require('./credentials.json');
const fs = require('fs')
const scopes = [
'https://www.googleapis.com/auth/drive',
'https://www.googleapis.com/auth/drive.file',
'https://www.googleapis.com/auth/drive.appdata',
];
const auth = new google.auth.JWT(
credentials.client_email, null,
credentials.private_key, scopes
);
const drive = google.drive({ version: "v3", auth });
auth.authorize(function(err, tokens) {
if (err) {
console.log(err);
return;
} else {
console.log('It authorized successfully!');
console.log(`The Token is: ${JSON.stringify(tokens)}`)
var data = fs.createReadStream('./Test.txt')
var fileMetadata = {
'name': 'photo.txt',
'parents':[{'id':'1MiFB-XXWFRHjxZwTmE9FxsCGb9Een_2Y'}] //Folder …Run Code Online (Sandbox Code Playgroud)