【问题标题】:How do I create a Google Sheets document via the Google Drive Javascript OAuth2 API?如何通过 Google Drive Javascript OAuth2 API 创建 Google Sheets 文档?
【发布时间】: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


    【解决方案1】:

    我有一个简单的方法可以使用名为 Cloud Snippets (cloudward.com) 的产品来实现这一点。您可以创建 sn-p 并嵌入到您的网站中。

    sn-p 可以像一个命令一样简单:

    <# create record for spreadsheet "create sheet example";
       set a to "";
       set b to "";
    #>
    

    这将创建一个包含名为“a”和“b”的列

    您实际上可以添加内容:

    <# create record for spreadsheet "create sheet example";
       set Name to "Bob";
       set Relation to "Uncle";
       set Email to "bob@example.com";
    #>
    

    【讨论】:

      猜你喜欢
      • 2016-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-16
      • 1970-01-01
      • 2017-08-29
      • 2016-07-22
      • 1970-01-01
      相关资源
      最近更新 更多