บริการขั้นสูงใน Apps Script ช่วยให้นักพัฒนาแอปที่มีประสบการณ์เชื่อมต่อกับ Google API สาธารณะบางรายการได้โดยไม่ต้องตั้งค่ามากเท่ากับการใช้อินเทอร์เฟซ HTTP บริการขั้นสูงเป็นเพียง Wrapper แบบบางๆ รอบ Google API เหล่านั้น โดยจะทำงานคล้ายกับบริการในตัวของ Apps Script เช่น มีการเติมข้อความอัตโนมัติ และ Apps Script จะจัดการขั้นตอนการให้สิทธิ์โดยอัตโนมัติ อย่างไรก็ตาม คุณต้องเปิดใช้บริการขั้นสูงก่อนจึงจะใช้ในสคริปต์ได้
หากต้องการดูว่า Google API ใดบ้างที่พร้อมให้บริการเป็นบริการขั้นสูง ให้ดูส่วนบริการขั้นสูงของ Google ในข้อมูลอ้างอิง หากต้องการใช้ Google API ที่ไม่พร้อมให้บริการเป็นบริการขั้นสูง เพียงเชื่อมต่อกับ API นั้นเหมือนกับAPI ภายนอกอื่นๆ
บริการขั้นสูงหรือ HTTP
บริการขั้นสูงของ Google แต่ละรายการจะเชื่อมโยงกับ Google API สาธารณะ ใน Apps Script คุณสามารถเข้าถึง API เหล่านี้ผ่านบริการขั้นสูงหรือโดยการส่งคำขอ API โดยตรงโดยใช้ UrlFetch
หากใช้วิธีบริการขั้นสูง Apps Script จะจัดการขั้นตอนการให้สิทธิ์และรองรับการเติมข้อความอัตโนมัติ อย่างไรก็ตาม คุณต้องเปิดใช้บริการขั้นสูงก่อนจึงจะใช้ได้ นอกจากนี้ บริการขั้นสูงบางอย่างยังให้ฟังก์ชันการทำงานเพียงบางส่วนที่พร้อมใช้งานใน API เท่านั้น
หากคุณใช้UrlFetchเมธอดเพื่อเข้าถึง API โดยตรง คุณจะถือว่า Google API เป็นAPI ภายนอก วิธีนี้ช่วยให้ใช้ API ได้ทุกด้าน แต่คุณจะต้องจัดการการให้สิทธิ์ API ด้วยตนเอง นอกจากนี้ คุณยังต้องสร้างส่วนหัวที่จำเป็นและแยกวิเคราะห์ การตอบกลับจาก API ด้วย
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2025-08-04 UTC"],[[["\u003cp\u003eApps Script's advanced services simplify connections to Google APIs, offering features like autocomplete and automatic authorization handling.\u003c/p\u003e\n"],["\u003cp\u003eChoose between advanced services or the \u003ccode\u003eUrlFetch\u003c/code\u003e method for API access, weighing the convenience of advanced services against the flexibility of \u003ccode\u003eUrlFetch\u003c/code\u003e for full API functionality.\u003c/p\u003e\n"],["\u003cp\u003eEnable advanced services in your script project and potentially the corresponding API in your Google Cloud Platform project for access.\u003c/p\u003e\n"],["\u003cp\u003eMethod signatures in Apps Script for advanced services are generally derived from the structure of corresponding public Google APIs.\u003c/p\u003e\n"],["\u003cp\u003eRefer to the support resources for the specific underlying API when facing issues with advanced services, as they act as wrappers for those APIs.\u003c/p\u003e\n"]]],[],null,["The advanced services in Apps Script let experienced developers connect to\ncertain public Google APIs with less set-up than using their HTTP interfaces.\nAdvanced services are essentially thin wrappers around those Google APIs. They\nwork much like Apps Script's\n[built-in services](/apps-script/guides/services)---for example, they offer\nautocomplete, and Apps Script handles the\n[authorization flow](/apps-script/guides/services/authorization) automatically.\nHowever, you must [enable an advanced service](#enable_advanced_services) before\nyou can use it in a script.\n\nTo see which Google APIs are available as advanced services, look for the\n**Advanced Google Services** section in the\n[Reference](/apps-script/reference). If you want to use a Google API that\nisn't available as an advanced service, just connect to it like any other\n[external API](/apps-script/guides/services/external).\n\nAdvanced services or HTTP?\n\nEach of the advanced Google services is associated with a public Google API.\nIn Apps Script, you can access these APIs via advanced services or by simply\nmaking the API requests directly using\n[`UrlFetch`](/apps-script/reference/url-fetch).\n\n**If you use the advanced service method** , Apps Script handles the\n[authorization flow](/apps-script/guides/services/authorization) and offers\nautocomplete support. However, you must\n[enable the advanced service](#enable_advanced_services) before you can use\nit. In addition, some advanced services only provide a subset of the\nfunctionality available in the API.\n\n**If you use the `UrlFetch` method to access the API directly** , you are\nessentially treating the Google API as an\n[external API](/apps-script/guides/services/external). With this method, all\naspects of the API can be used. However, it requires you to handle the API\nauthorization yourself. You must also construct any needed headers and parse\nthe API responses.\n\nIn general it's easiest to use an advanced service where possible and only\nuse the `UrlFetch` method when the advanced service doesn't provide the\nfunctionality you need.\n\nRequirements\n\nBefore you can use an advanced service, you must satisfy the following\nrequirements:\n\n1. You must [enable the advanced service](/apps-script/guides/services/advanced#enable_advanced_services) in your script project.\n2. You must make sure the API corresponding to the advanced service is enabled\n in the [Cloud Platform (GCP) project](/apps-script/guides/cloud-platform-projects)\n your script uses.\n\n If your script project uses a [default GCP project](/apps-script/guides/cloud-platform-projects#default_cloud_platform_projects)\n created on or after April 8, 2019, the API is enabled automatically\n after you enable the advanced service and save the script project. If you\n have not done so already, you may also be\n asked to agree to the [Google Cloud](https://cloud.google.com/terms/)\n and [Google APIs](/terms) Terms of Service as well.\n\n If your script project uses a\n [standard GCP project](/apps-script/guides/cloud-platform-projects#standard_cloud_platform_projects)\n or an older default GCP project,\n you must [enable the advanced service's corresponding API](/apps-script/guides/cloud-platform-projects#enabling_an_api_in_a_standard_gcp_project)\n in the GCP project manually. You must have edit access to the GCP project\n to make this change.\n\nSee [Cloud Platform projects](/apps-script/guides/cloud-platform-projects)\nfor more information.\n\nEnable advanced services\n\nTo use an advanced Google service, follow these instructions:\n\n1. Open the Apps Script project.\n2. At the left, click **Editor** code.\n3. At the left, next to **Services** , click **Add a service** add.\n4. Select an advanced Google service and click **Add**.\n\n| **Note:** If you're using a [standard GCP project](/apps-script/guides/cloud-platform-projects#standard_cloud_platform_projects) (or an older default GCP project that was created prior to April 8, 2019), you must also manually enable the API corresponding to the advanced service. Enable the API by doing the following:\n|\n| 1. Open the GCP project associated with your script in the [**Google Cloud console**](https://console.developers.google.com/apis/dashboard).\n| 2. At the top of the console, click into the search bar and type part of the name of the API (for example, \"Calendar\"), then click the name once you see it.\n| 3. On the next screen, click **Enable API**.\n| 4. Close the Google Cloud console and return to the script editor. Click **OK** in the dialog.\n\nAfter you enable an advanced service, it's available in autocomplete.\n\nHow method signatures are determined\n\nAdvanced services generally use the same objects, method names, and parameters\nas the corresponding public APIs, although method signatures are translated for\nuse in Apps Script. The script editor's\n[autocomplete function](/apps-script/guides/services#using_autocomplete)\nusually provides enough information to get started, but the rules below explain\nhow Apps Script generates a method signature from a public Google API.\n\nRequests to Google APIs can accept a variety of different types of data,\nincluding path parameters, query parameters, a request body, and/or a media\nupload attachment. Some advanced services can also accept specific HTTP request\nheaders (for example, the\n[Calendar advanced service](/apps-script/advanced/calendar)).\n\nThe corresponding method signature in Google Apps Script has the following\narguments:\n\n1. The request body (usually a resource), as a JavaScript object.\n2. Path or required parameters, as individual arguments.\n3. The media upload attachment, as a [`Blob`](/apps-script/reference/base/blob) argument.\n4. Optional parameters, as a JavaScript object mapping parameter names to values.\n5. HTTP request headers, as a JavaScript object mapping header names to header values.\n\nIf the method doesn't have any items in a given category, that part of the\nsignature is omitted.\n\nThere are some special exceptions to be aware of:\n\n- For methods that accept a media upload, the parameter `uploadType` is set automatically.\n- Methods named `delete` in the Google API are named `remove` in Apps Script, since `delete` is a reserved word in JavaScript.\n- If an advanced service is configured to accept HTTP request headers, and you set a request headers JavaScript object, then you must also set the optional parameters JavaScript object (to an empty object if you aren't using optional parameters).\n\nSupport for advanced services\n\nAdvanced services are just thin wrappers that enables the use of a Google\nAPIs within Apps Script. As such, any issue encountered while using them is\nusually an issue with the underlying API, not with Apps Script itself.\n\nIf you encounter a problem while using an advanced service, it should be\nreported using the support instructions for the underlying API. Links to these\nsupport instructions are provided in each advanced service guide in the\nApps Script [Reference](/apps-script/reference) section."]]