[英]How do I create a Google Sheets document via the Google Drive Javascript OAuth2 API?
I am trying to create a blank Google Sheets document in Google Drive from a browser based app. 我正在尝试通过基于浏览器的应用程序在Google云端硬盘中创建空白的Google表格文档。 I am able to create a blank file with an unknown file type, but have not been able to create a Google Sheets document. 我能够创建一个文件类型未知的空白文件,但无法创建Google表格文档。
My code is as follows: 我的代码如下:
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);
});
}
I have reviewed the documentation here: https://developers.google.com/drive/v2/reference/files/insert 我在这里查看了文档: https : //developers.google.com/drive/v2/reference/files/insert
And the following StackOverflow posts: Creating empty spreadsheets in Google Drive using Drive API (in Python) How to create an empty Google doc / Spreadsheet 以下是StackOverflow的帖子: 使用Drive API在Google Drive中创建空电子表格(在Python中) 如何创建空Google文档/电子表格
I realise that I need to use a mimeType of 'application/vnd.google-apps.spreadsheet'. 我意识到我需要使用mimeType为“ application / vnd.google-apps.spreadsheet”。
I have also been able to successfully create a blank Google Sheets document using the APIs Explorer, but have been unable to determine how this is working. 我还能够使用API资源管理器成功创建空白的Google表格文档,但无法确定其工作方式。 It is doing a post request to: 它正在发出以下请求:
With a request payload of: 请求有效负载为:
{ "title": "This is a test", "mimeType": "application/vnd.google-apps.spreadsheet" } {“ title”:“这是一个测试”,“ mimeType”:“ application / vnd.google-apps.spreadsheet”}
But note that the URL is slightly different. 但是请注意,URL略有不同。
I have an easy way to do this with a product called Cloud Snippets (cloudward.com). 我有一种简单的方法,可以使用名为Cloud Snippets(cloudward.com)的产品来做到这一点。 You can create the snippet and embed into your web site. 您可以创建代码段并嵌入到您的网站中。
The snippet could be as easy as one command: 该代码段就像一个命令一样简单:
<# create record for spreadsheet "create sheet example";
set a to "";
set b to "";
#>
this creates a sheet with columns named "a" and "b" 这将创建一个包含名为“ a”和“ b”的列的工作表
you could actually add content: 您实际上可以添加内容:
<# create record for spreadsheet "create sheet example";
set Name to "Bob";
set Relation to "Uncle";
set Email to "bob@example.com";
#>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.