简体   繁体   English

在Google Apps脚本上使用Google Script API获取开发人员元数据

[英]Getting Developer Metadata using Google Script API on Google Apps Script

I am trying to get the developer metadata about a spreadsheet using the Google Script API, as found on this website. 我正在尝试使用此网站上的Google Script API获取有关电子表格的开发人员元数据。

https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.developerMetadata/search https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.developerMetadata/search

I have tried the following, however I am getting no response back? 我已经尝试了以下方法,但是没有得到回复? Can anyone see where I am going wrong? 谁能看到我要去哪里错了?

    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var fileId = ss.getId();
    var token = ScriptApp.getOAuthToken();

    var paramsPost = {
        method: 'post',
        headers: {
            Authorization: 'Bearer ' + token
        },
        muteHttpExceptions: true,
        contentType: 'application/json',
        payload: JSON.stringify({
            dataFilters: [{
                developerMetadataLookup: {
                    locationType: 'COLUMN'
                }
            }]
        })
    };

    var url = 'https://sheets.googleapis.com/v4/spreadsheets/' + fileId + '?developerMetadata:search';
    var res = UrlFetchApp.fetch(url, paramsPost);
    var data = JSON.parse(res.getContentText());

You no longer need to use the REST API directly to access developer metadata. 您不再需要直接使用REST API来访问开发人员元数据。

As of November 14, 2018, methods to access developer metadata were added to the built-in Spreadsheet service. 从2018年11月14日开始,内置的Spreadsheet服务中添加了用于访问开发人员元数据的方法。 See Release Notes for details. 有关详细信息,请参见发行说明

In order to use the method of spreadsheets.developerMetadata.search of Sheets API, please modify the endpoint as follows. 为了使用Sheets API的电子表格sheets.developerMetadata.search的方法,请按如下所示修改端点。

From: 从:

var url = 'https://sheets.googleapis.com/v4/spreadsheets/' + fileId + '?developerMetadata:search';

To: 至:

var url = 'https://sheets.googleapis.com/v4/spreadsheets/' + fileId + '/developerMetadata:search';
  • ? of '?developerMetadata:search' is / . '?developerMetadata:search'值为/

Reference: 参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM