小编Sal*_*dor的帖子

将文件上传到状态 200 的 Google Drive API,但该文件在哪里?

我正在尝试将文件上传到 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)

javascript node.js google-drive-api

3
推荐指数
1
解决办法
1443
查看次数

标签 统计

google-drive-api ×1

javascript ×1

node.js ×1