0

I created a script following "Ruby Quickstart" but I can't run it with the API.

I know that I should publish it as API executable. To do that I need to switch the script project to use a "standard GCP project" and I couldn't find how to do it from the API.

If I switch it manually it works. When I execute the code below I get this error:

> 403, PERMISSION_DENIED: The caller does not have permission

This is the code:

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
the Tin Man
  • 158,662
  • 42
  • 215
  • 303

1 Answers1

0

I am sorry to inform you that this operation is not possible. You need to use a standard browser interface (read as not an API) to switch a GCP project as described here. On this docs you can find more information about how to use Apps Script on your app, and here you can learn how to activate any API (included Apps Scripts API).

Jacques-Guzel Heron
  • 2,480
  • 1
  • 7
  • 16