RFF*_*RFF 3 javascript google-drive-api
我正在尝试了解如何使用客户端Javascript访问Google云端硬盘.我写了一些测试代码来插入一个只有元数据的新文件.我找到了一个使用此代码的示例:
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"
}
});
Run Code Online (Sandbox Code Playgroud)
上面的代码工作正常,但它不使用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} );
Run Code Online (Sandbox Code Playgroud)
这段代码也可以,所以我的问题是我应该使用哪些?有没有理由使用像files.insert这样的各种api调用,还是应该总是使用gapi.client.request来处理所有事情?
You actually have three choices ...
Underlying each option is the same HTTP request/response so the functionality is the same. It probably comes down to personal preference and trust.
Personal preference Do you want to understand what your app is doing all the way down the stack, or do you prefer to use a high level abstraction?
Trust, The Google JS library is closed source, and is updated arbitrarily, and without warning. So if the G engineers break it (as they have done in the past), you have nowhere to turn and your app is down until it is fixed. Provided you have a mainstream use case, it should get fixed, but there is no guarantee. If you are using an edge case (perhaps an unusual nodejs configuration, or idiosyncratic browser) you could be left high and dry.
我个人使用选项1,因为如果Drive团队向API添加新功能,我可以立即使用它,而无需等待JS Client Library维护人员也支持它.它还使调试更容易,因为通过线路的内容与我的代码直接相关.
现在Drive支持CORS上传,我正在从选项1迁移到选项3.如果你想构建chrome扩展或打包的应用程序,选项3也是唯一可行的选项.
归档时间: |
|
查看次数: |
1726 次 |
最近记录: |