小编Nic*_*iks的帖子

使用 javascript(无 html 表单)以编程方式将文件上传到 Google Drive

编辑:我是一个假人。文档在这里清楚地说明了这一点:https : //developers.google.com/drive/v3/web/manage-uploads

上下文的项目概述:我正在使用 node.js 编写部署在 Heroku 上的 twitter 机器人。我希望这个机器人能够从 Google Drive 下载 .txt 文件(或 .ini 或其他文件),使用该文件撰写推文,编辑文本文件的正文以反映生成的推文,然后覆盖 Google Drive 中的原始文件。它将始终下载、编辑和覆盖同一个文件,因此不需要文件选择对话框。

具体问题:我无法弄清楚如何在不使用 html 页面的情况下实际上传文本文件的正文。这一切都应该发生在没有用户交互的服务器端。我发现的大多数示例似乎都使用 html 页面来收集和发送文件信息,但我使用的是纯 javascript,因此这不适用于我的项目。我已经在 Google Drive API 文档中搜索了示例,但到目前为止还没有运气。

到目前为止的代码:

中间的评论块是我遇到麻烦的地方。

authClientUp.authorize(function(err, tokens) {
    if (err) {
        console.log(err);
        return;                                                     
    } else {
        console.log('It authorized successfully!');
        drive.files.insert({           // ---- For the purposes of getting
            auth: authClientUp,        // ---- started, I'm just creating
            "title": "file1.txt",      // ---- a new file instead of overwriting
            "mimeType": "text/plain",  // ---- an …
Run Code Online (Sandbox Code Playgroud)

javascript node.js google-drive-api

2
推荐指数
1
解决办法
8437
查看次数

标签 统计

google-drive-api ×1

javascript ×1

node.js ×1