如何使用Google Apps脚本将JSON文件保存到Google云端硬盘? [英] How to Save a JSON file to Google Drive using Google Apps Script?

查看:49
本文介绍了如何使用Google Apps脚本将JSON文件保存到Google云端硬盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个神经网络脚本,需要来自JSON文件的训练数据,是否可以使用Google Apps脚本将JSON文件保存到Google云端硬盘?

I have a neural network script that requires training data from a JSON file, is it possible to save a JSON file to Google Drive using Google Apps Script?

推荐答案

您可以使用必须启用的高级驱动器服务.
在Apps脚本代码编辑器中:

You can use the Advanced Drive Service, which must be enabled.
From the Apps Script code editor:

  • 资源"菜单
  • 高级Google服务"
  • 在列表中找到"Drive API"
  • 单击按钮将其打开

过去,您还需要在Google Cloud Platform中启用Drive API.但是现在您有两种选择.

In the past, you needed to also enable the Drive API in the Google Cloud Platform. But now you have two choices.

  • 使用默认" Google Cloud项目-您无需在Google Cloud Platform中显式启用Drive API.
  • 创建一个新的标准" Google Cloud项目,并将其与您的Apps Script项目相关联.您需要在Google Cloud Platform中启用Drive API.

如果Apps Script项目将成为普通大众使用的项目,那么您应该创建一个标准" Google Cloud项目,并在Google Cloud Platform中启用Google Drive API.

If the Apps Script project is going to be something used by the general public, then you should create a "standard" Google Cloud project, and enable the Google Drive API in the Google Cloud Platform.

function saveAsJSON() {
  var blob,file,fileSets,obj;

  obj = {//Object literal for testing purposes
    key:"value"
  }

/**
 * Creates a file in the users Google Drive
 */

  fileSets = {
    title: 'AAA_Test.json',
    mimeType: 'application/json'
  };

  blob = Utilities.newBlob(JSON.stringify(obj), "application/vnd.google-apps.script+json");
  file = Drive.Files.insert(fileSets, blob);
  Logger.log('ID: %s, File size (bytes): %s, type: %s', file.id, file.fileSize, file.mimeType);

}

这篇关于如何使用Google Apps脚本将JSON文件保存到Google云端硬盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆