我试图了解如何最好地使用客户端 Javascript 访问 Google Drive。我写了一些测试代码来插入一个只有元数据的新文件。我找到了一个使用此代码的示例:
var request = gapi.client.request({
'path': '/drive/v2/files',
'method': 'POST',
'body': {
"title" : "Meta File 1.json",
"mimeType" : "application/json",
"description" : "This is a test of creating a metafile"
}
});
上面的代码运行良好,但没有使用 gapi.client.drive.files.insert。所以我搜索了stackoverflow并尝试了下面的代码:
var mydata = {};
mydata.title = "Meta File using Insert.json";
mydata.mimeType = "application/json";
mydata.description = "We are using insert to create a new file, but only the metadata.";
var request = gapi.client.drive.files.insert( {'resource': mydata} );
这段代码也可以正常工作,所以我的问题是我应该使用哪个?是否有任何理由使用各种 api 调用,如 files.insert,或者我应该总是使用 gapi.client.request 来处理所有事情?