如何使用Google API服务库(Node.js)运行Google App脚本 [英] How to run a Google App Script using Google API Service Library (Node.js)

查看:97
本文介绍了如何使用Google API服务库(Node.js)运行Google App脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照Google Apps脚本> Rest API Node.js快速入门示例,我能够完成身份验证过程(跟随链接,获取令牌,存储令牌)

By following the Google Apps Script > Rest API Node.js quickstart example I am able to complete the authentication process (follow the link, get a token, store the token)

但是脚本执行失败并显示错误消息

but the script execution fails with the error message

The API returned an error: Error: Project title may not be empty.

project.create()的文档指示请求正文仅需要包含{title:string},即快速入门的内容.

The documentation for project.create() indicates the request body only need contain {title:string} which what the quickstart has.

仔细检查Google Apps Script API是否已启用=是,但是api启用页面显示了一些不应包含的html代码,并启用了该代码以供使用

Double check Google Apps Script API is enabled = yes,but the api enable page shows some html code it shouldn't, and the enable it for use url in the Overview sections of that page is broken.

我很确定启用API,因为我在console.cloud中看到了流量

I pretty sure the API is enabled as I see traffic in console.cloud

方法看起来像这样.

  script.projects.create({
    auth,
    resource: {
      title: 'My Script'
    }
  });

我还尝试了auth:auth,因为这是我在其他地方看到的工作(错误消息msg)

I also tried auth: auth as that is what I have seen working elsewhere (same error msg)

错误堆栈如下所示.

The error stack looks like this.

换句话说,我完全遵循了快速入门,并检查了功能文档无济于事,能帮上什么忙吗?

In other words, I followed the quick start exactly and checked function documentation to no avail, can some one help?

推荐答案

我认为您的请求正文有效.那么您可以确认以下几点吗?

I think that your request body works. So can you confirm the following points?

  1. 您使用的是哪个版本?在我的环境中,无法使用v25.0.0-v30.0.0的googleapis.我确认使用v24.0.0的googleapis可以正常工作.
    • 使用v24.0.0时,如果脚本使用var {google} = require('googleapis');,请修改为var google = require('googleapis');.
  1. What version are you using? In my environment, googleapis with v25.0.0 - v30.0.0 cannot be worked. I confirmed that googleapis with v24.0.0 works fine.
    • When you use v24.0.0, if your script use var {google} = require('googleapis');, please modify to var google = require('googleapis');.

注意:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆