Apps Script 함수 실행
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Apps Script API (이전의 Apps Script Execution API)를 사용하면 액세스 권한이 있는 스크립트 프로젝트에서 함수를 원격으로 실행할 수 있습니다. 앱은 필요한 경우 입력 매개변수를 제공하여 지정된 Apps Script 함수를 호출하고 반환된 응답을 수신할 수 있습니다.
이 페이지의 예에서는 API를 사용하여 일반적인 실행 작업을 수행하는 방법을 보여줍니다. 특수 승인 요구사항을 포함한 자세한 내용은 함수 실행 가이드를 참고하세요.
이 예시에서는 스크립트 프로젝트 ID를 제공할 위치를 나타내기 위해 자리표시자 scriptId가 사용됩니다. 스크립트 ID를 찾으려면 아래 단계를 따르세요.
- Apps Script 프로젝트의 왼쪽 상단에서 프로젝트 설정
settings을 클릭합니다.
- '스크립트 ID' 옆에 있는 복사를 클릭합니다.
함수 실행
다음 scripts.run 요청은 listFolderContent
라는 Apps Script 함수를 호출하여 Drive folderId과 정수 MAX_SIZE
를 인수로 전달합니다. 함수는 개발 모드에서 실행됩니다. 즉, 실행 파일로 배포된 버전과 관계없이 가장 최근에 저장된 버전의 함수가 실행됩니다.
요청 프로토콜은 다음과 같습니다. 함수 실행 가이드에서는 Google API 클라이언트 라이브러리를 사용하여 다양한 언어로 실행 요청을 구현하는 방법을 보여줍니다.
POST https://script.googleapis.com/v1/scripts/scriptId:run
{
"function": "listFolderContent",
"parameters": [
folderId,
MAX_SIZE
],
"devMode": true
}
호출된 Apps Script 함수가 완료되면 이 요청에 대한 응답에는 실행 결과 또는 오류 응답이 포함됩니다. 이 예에서 함수는 파일 이름 배열을 성공적으로 반환합니다.
{
"response": {
"result": [
"fileTitle1",
"fileTitle2",
"fileTitle3"
]
},
}
Apps 스크립트 실행 중에 함수에 오류가 발생한 경우 응답은 다음과 같을 수 있습니다.
{
"response": {
"error": {
"code": 3,
"message": "ScriptError",
"details": [{
"@type": "type.googleapis.com/google.apps.script.v1.ExecutionError",
"errorMessage": "The script enountered an exeception it could not resolve.",
"errorType": "ScriptError",
"scriptStackTraceElements": [{
"function": "listFolderContent",
"lineNumber": 14
}]
}]
}
}
}
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-08-31(UTC)
[null,null,["최종 업데이트: 2025-08-31(UTC)"],[[["\u003cp\u003eThe Apps Script API enables remote execution of functions within your accessible script projects.\u003c/p\u003e\n"],["\u003cp\u003eYou can provide input parameters to the functions and receive corresponding responses.\u003c/p\u003e\n"],["\u003cp\u003eRefer to the "Executing a function" guide for comprehensive information, including authorization requirements.\u003c/p\u003e\n"],["\u003cp\u003eThe provided examples demonstrate how to execute functions and handle potential errors using the API.\u003c/p\u003e\n"]]],[],null,["# Executing Apps Script Functions\n\nThe Apps Script API (and formerly the Apps Script Execution API) allows you\nto remotely execute a function in a script project you have access to. Your\napp can call a given Apps Script function, providing it input parameters if\nneeded, and receive a returned response.\n\nThe examples on this page illustrate how some common execution operations can\nbe achieved with the API. For more information **including special\n[authorization requirements](/apps-script/api/how-tos/execute#requirements)** ,\nsee the [Executing a function](/apps-script/api/how-tos/execute) guide.\n\nIn these examples, the placeholders \u003cvar translate=\"no\"\u003escriptId\u003c/var\u003e\nis used to indicate where you would provide the script project ID. Follow the\nsteps below to find the script ID:\n\n1. In the Apps Script project, at the top left, click **Project Settings** settings.\n2. Next to \"Script ID,\" click **Copy**.\n\nExecute a function\n------------------\n\nThe following [scripts.run](/apps-script/api/reference/rest/v1/scripts/run)\nrequest calls an Apps Script function named `listFolderContent`, passing it\nthe Drive \u003cvar translate=\"no\"\u003efolderId\u003c/var\u003e and an integer `MAX_SIZE` as arguments. The\nfunction is executed in development mode, meaning that the most recently\nsave version of the function is executed, regardless of what version is\ndeployed as an executable.\n\nThe request protocol is shown below. The\n[Executing functions](/apps-script/api/how-tos/execute) guide\nshows how to implement a run request in different languages using the Google\nAPI client libraries. \n\n```\nPOST https://script.googleapis.com/v1/scripts/scriptId:run\n``` \n\n```scdoc\n{\n \"function\": \"listFolderContent\",\n \"parameters\": [\n folderId,\n MAX_SIZE\n ],\n \"devMode\": true\n}\n```\n\nThe [response](/apps-script/api/reference/rest/v1/scripts/run#response-body)\nto this request, once the called Apps Script function completes,\ncontains the results of the execution or an error response. In\nthis example, the function successfully returns an array of file names: \n\n```text\n{\n \"response\": {\n \"result\": [\n \"fileTitle1\",\n \"fileTitle2\",\n \"fileTitle3\"\n ]\n },\n}\n```\n\nIf the function encountered an error during the Apps Script execution, the\nresponse could look like this: \n\n```carbon\n{\n \"response\": {\n \"error\": {\n \"code\": 3,\n \"message\": \"ScriptError\",\n \"/apps-script/api/reference/rest/v1/ExecutionError\": [{\n \"@type\": \"type.googleapis.com/google.apps.script.v1.ExecutionError\",\n \"errorMessage\": \"The script enountered an exeception it could not resolve.\",\n \"errorType\": \"ScriptError\",\n \"/apps-script/api/reference/rest/v1/ExecutionError#ScriptStackTraceElement\": [{\n \"function\": \"listFolderContent\",\n \"lineNumber\": 14\n }]\n }]\n }\n }\n}\n```"]]