【发布时间】:2015-04-22 04:56:11
【问题描述】:
我正在尝试通过基于浏览器的应用在 Google 云端硬盘中创建一个空白的 Google 表格文档。我能够创建文件类型未知的空白文件,但无法创建 Google 表格文档。
我的代码如下:
function createfile() {
var config = {
'client_id': '<putyourclient_idhere>',
'scope': 'https://www.googleapis.com/auth/drive'
};
gapi.auth.authorize(config, function() {
var request = gapi.client.request({
'path': '/upload/drive/v2/files',
'method': 'POST'
});
var callback = function(file) {
console.log(file)
};
request.execute(callback);
});
}
我在这里查看了文档:https://developers.google.com/drive/v2/reference/files/insert
还有以下 StackOverflow 帖子: Creating empty spreadsheets in Google Drive using Drive API (in Python) How to create an empty Google doc / Spreadsheet
我意识到我需要使用 'application/vnd.google-apps.spreadsheet' 的 mimeType。
我还能够使用 APIs Explorer 成功创建一个空白的 Google 表格文档,但无法确定它是如何工作的。它正在发出一个发布请求:
请求负载为:
{ "title": "这是一个测试", "mimeType": "application/vnd.google-apps.spreadsheet" }
但请注意,网址略有不同。
【问题讨论】:
标签: javascript google-api google-sheets