首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用Apps脚本API创建和执行函数

如何使用Apps脚本API创建和执行函数
EN

Stack Overflow用户
提问于 2020-03-30 11:00:34
回答 1查看 102关注 0票数 0

我创建了一个跟在"Ruby Quickstart“后面的脚本,但是我不能用API运行它。

我知道我应该把它作为API可执行文件发布。要做到这一点,我需要将脚本项目切换为使用"standard GCP project“,但我无法从API中找到如何做到这一点。

如果我手动切换它,它就能工作。当我执行下面的代码时,我得到了这个错误:

代码语言:javascript
运行
复制
> 403, PERMISSION_DENIED: The caller does not have permission

代码如下:

代码语言:javascript
运行
复制
def create_and_execute
  # Initialize the API
  service = Google::Apis::ScriptV1::ScriptService.new
  service.client_options.application_name = APPLICATION_NAME
  service.authorization = authorize

  # Make the API request.
  request = Google::Apis::ScriptV1::CreateProjectRequest.new(
  title: "My Script3"
  )
  resp = service.create_project request

  script_id = resp.script_id
  content = Google::Apis::ScriptV1::Content.new(
  files:     [
    Google::Apis::ScriptV1::File.new(
    name:   "hello",
    type:   "SERVER_JS",
    source: "function helloWorld() {\n  console.log('Hello, world!');\n}"
    ),
    Google::Apis::ScriptV1::File.new(
    name:   "appsscript",
    type:   "JSON",
    source: "{\"timeZone\":\"America/Los_Angeles\",\"exceptionLogging\":\"CLOUD\",\"executionApi\":{\"access\":\"ANYONE\"}}"
    )
],
script_id: script_id
)

service.update_project_content(script_id, content)    
service.create_project_version(script_id,Google::Apis::ScriptV1::Version.new(script_id: script_id))
service.create_project_deployment(script_id,Google::Apis::ScriptV1::DeploymentConfig.new(script_id: script_id,version_number: 1))
service.run_script(script_id, Google::Apis::ScriptV1::ExecutionRequest.new(function: 'helloWorld', dev_mode: true))
  end
EN

回答 1

Stack Overflow用户

发布于 2020-03-30 22:42:46

我很抱歉地通知您,这个操作是不可能的。您需要使用标准浏览器界面(读作不是API)来切换GCP项目,如here所述。在this文档中,你可以找到更多关于如何在你的应用程序上使用应用程序脚本的信息,而here你可以学习如何激活任何应用程序接口(包括应用程序脚本API)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60923436

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档