Apps脚本高级驱动器API服务 - newFile()方法不创建文件 [英] Apps Script Advanced Drive API Service - newFile() Method not Creating a File

查看:89
本文介绍了Apps脚本高级驱动器API服务 - newFile()方法不创建文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Advanced Drive API服务的 newFile()方法似乎会返回一个对象,但不会在我的Google云端硬盘中创建文件。我找不到任何文件。这里是我试过的代码和结果。

var file = Drive.newFile();
Logger.log('file'+ file);

file = {one:value One};
Logger.log('file'+ file);

Logger.log(file ['one']+ file ['one']);
};

LOGS列印此:


文件{}



文件[object Object]

文件['one'] value One


我尝试在 newFile()括号内添加一个字符串:

 函数makeNewDoc(){

var file = Drive.newFile(some text);
Logger.log('file'+ file);

file = {one:value One};
Logger.log('file'+ file);

Logger.log(file ['one']+ file ['one']);
$ b $(var key in file){
Logger.log('key:'+ key);
Logger.log('value:'+ file [key]);
};
};

这并不会产生错误,但它也不会执行任何操作。或者我不知道它在做什么。



我多次运行代码后多次检查过我的Google驱动器,并且我的系统中没有新文件Drive


$ b $ newFile()方法返回一个对象,我可以放入新的属性,然后枚举。但除此之外,我不知道它做了什么,或者它有什么用处。

所以,如果有人能告诉我 newFile ()方法,我真的很想知道。

解决方案

是一个示例如何使用高级Drive服务创建新文档

 函数createNewDoc(title,content,folderId) {

var content = content || ;

//无论是kind还是mimeType属性似乎都是必需的
//用于创建文档,但包含任何内容
var resource = {
title: title,
parents:[
{
id:folderId,
kind:drive#fileLink
}
],
mimeType:'application / vnd.google-apps.document'
};

var blob = Utilities.newBlob(content);
var newfile = Drive.Files.insert(resource,blob,{convert:true});

返回newFile;
}


The newFile() method of the Advanced Drive API Service seems to return an object, but not create a file in my Google Drive. I can't find any documentation for this. Here is code that I tried, and the results I got.

function makeNewDoc() { 

  var file = Drive.newFile();
  Logger.log('file ' + file);

  file = {one: "value One"};
  Logger.log('file ' + file);

  Logger.log("file['one'] " + file['one']);
};

The LOGS print this:

file {}

file [object Object]

file['one'] value One

I tried adding a string inside the newFile() parenthesis:

function makeNewDoc() { 

  var file = Drive.newFile("some text");
  Logger.log('file ' + file);

  file = {one: "value One"};
  Logger.log('file ' + file);

  Logger.log("file['one'] " + file['one']);

  for (var key in file) {
     Logger.log('key: ' + key);
     Logger.log('value: ' + file[key]);
  };
};

That didn't produce an error, but it doesn't do anything either. Or I don't know what it's doing.

I've checked my Google drive many times after running the code many times, and there is never a new file in my Drive.

The newFile() method returns an object, that I can put new properties into, and then enumerate. But other than that, I have no idea what it does, or what use it has.

So, if anyone can tell me what the newFile() method, of the Drive API does, I would really like to know.

解决方案

Below is an example how to make a new document with advanced Drive service

function createNewDoc(title,content,folderId){

  var content = content || "";

  // neither kind or mimeType properties seem to be necessary
  // for Doc to be created, but are being included anyhow 
  var resource = {
    title: title,
    parents: [
      {
        "id": folderId,
        "kind": "drive#fileLink"
      }
    ],
    mimeType: 'application/vnd.google-apps.document'
  };

  var blob = Utilities.newBlob(content);
  var newfile = Drive.Files.insert(resource, blob, {"convert":"true"});

  return newFile;
}

这篇关于Apps脚本高级驱动器API服务 - newFile()方法不创建文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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