本頁面中的部分或全部資訊可能不適用於 Trusted Cloud by S3NS。
必備條件
本文件說明使用 Compute Engine API 的必要條件。
開始編寫第一個用戶端應用程式之前,您必須先完成以下程序 (如果尚未完成)。
建立 Google 帳戶
您需要 Google 帳戶才能存取 Compute Engine API。如果您已擁有帳戶,表示您已具備存取權。
您可能也想要另外有個測試用的 Google 帳戶。
註冊並試用 Compute Engine
如要開始使用,您可以使用下列指南之一,在 Compute Engine 上建立 VM 執行個體:
繼續操作前,請務必熟悉 Compute Engine。API 說明文件假設您先前使用過 Compute Engine,也熟悉網路程式設計概念和網路資料格式。
瞭解驗證
您可以透過不同的方式驗證 Compute Engine,具體取決於您存取 API 的方式。詳情請參閱「對 Compute Engine 進行驗證」。
瞭解 REST
您可以透過下列兩種方式叫用 API:
如果您決定不使用用戶端程式庫,則必須瞭解 REST 的基本概念。
REST 基本概念
REST 是一種軟體架構,可提供簡便且一致的資料要求及修改方法。
REST 這個詞是「Representational State Transfer (表現層狀態轉換)」的簡稱。在 Google API 中,這是指使用 HTTP 動詞來擷取及修改 Google 所儲存資料的表示法。
在符合 REST 樣式的系統中,資源會儲存在資料儲存庫中。用戶端向伺服器發出執行特定動作 (例如建立、擷取、更新或刪除資源) 的要求後,伺服器就會執行指定動作並傳回回應 (大多採用指定資源表示法的形式)。
在具備 REST 特性的各種 Google API 中,用戶端會使用 POST
、GET
、PUT
或 DELETE
等 HTTP 動詞來指定動作。接著,該動詞會透過全域唯一的 URI 來指定資源,格式如下:
https://www.googleapis.com/apiName/apiVersion/resourcePath?parameters
由於所有 API 資源都有可供 HTTP 存取的專屬 URI,因此 REST 不僅能夠支援資料快取,也非常適合與網路的分散式基礎架構搭配運作。
您可以在 HTTP 1.1 標準說明文件中找到相當實用的方法定義,其中包括 GET
、POST
、PUT
及 DELETE
的規格說明。
Compute Engine API 中的 REST
Compute Engine API 作業會直接對應至 REST HTTP 動詞。
Compute Engine API 會使用下列格式建立 URI:
https://www.googleapis.com/compute/API_VERSION/RESOURCE_PATH
URI 包含下列值:
API_VERSION
:您要使用的 API 版本,對應至 Compute Engine 資源的發布階段,如下所示:
- 針對 GA 中的資源:
v1
- 公開測試版資源:
beta
- 非公開預先發布版的資源:
alpha
RESOURCE_PATH
:特定 Compute Engine 資源的路徑,例如 projects/example-project/aggregated/instances
。如要查看各個 API 版本的可用資源,請參閱下列資源:
如果您想加入查詢參數,請在 URI 中加入問號 (?
) 後方:
https://www.googleapis.com/compute/API_VERSION/RESOURCE_PATH?QUERY_PARAMETERS
在 URI 中,QUERY_PARAMETERS 是查詢參數清單,以半形連接號 (&
) 分隔,例如 format=json&filter=zone=us-central1-a
。
Compute Engine API 會以 JSON 格式傳回資料。
JSON (JavaScript Object Notation) 是一種常見的語言無關資料格式,可提供任意資料結構的簡單文字表示法。詳情請參閱 json.org。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-08 (世界標準時間)。
[[["容易理解","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-08 (世界標準時間)。"],[[["A Google Account is required to access Compute Engine in the Google APIs Console, and you may want a separate one for testing."],["You can create either a Linux or Windows VM instance to get started with Compute Engine, which is recommended for familiarization before using the API."],["Authentication to Compute Engine varies depending on your method of API access, and details can be found in the documentation provided."],["The Compute Engine API can be invoked through HTTP requests or by using client libraries, and using HTTP requests requires an understanding of REST principles."],["The Compute Engine API uses RESTful architecture, with operations mapping directly to HTTP verbs, and the API returns data in JSON format."]]],[]]