開始使用 Service Management API

本頁說明如何設定開發環境,以使用 Service Management API。使用 Service Management API 最簡單的方法 (除了使用Google Cloud 主控台網頁介面外),以及我們針對多數作業用途的建議,是透過gcloud 指令列介面。如需根據 Service Management API 編寫程式,建議您使用我們提供的其中一種用戶端程式庫。如要試用 API,請按照下方的替代設定指示操作,並使用 curl 指令試用 API,這樣就不必設定完整的應用程式開發環境。

使用 gcloud 設定

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Enable the Service Management API.

    Enable the API

  4. Install the Google Cloud CLI.

  5. 如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI

  6. 如要初始化 gcloud CLI,請執行下列指令:

    gcloud init
  7. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  8. Enable the Service Management API.

    Enable the API

  9. Install the Google Cloud CLI.

  10. 如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI

  11. 如要初始化 gcloud CLI,請執行下列指令:

    gcloud init
  12. 設定直接呼叫 API

    本節說明設定本機環境的基本必要步驟,以使用 curl 指令測試 Service Management API。本節內容專供需要根據 Service Management API 編寫程式的開發人員參考。

    初始設定

    1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
    2. Install the Google Cloud CLI.

    3. 如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI

    4. 如要初始化 gcloud CLI,請執行下列指令:

      gcloud init
    5. Create or select a Google Cloud project.

      • Create a Google Cloud project:

        gcloud projects create PROJECT_ID

        Replace PROJECT_ID with a name for the Google Cloud project you are creating.

      • Select the Google Cloud project that you created:

        gcloud config set project PROJECT_ID

        Replace PROJECT_ID with your Google Cloud project name.

    6. Enable the Service Management API:

      gcloud services enable servicemanagement.googleapis.com
    7. Grant roles to your user account. Run the following command once for each of the following IAM roles: roles/servicemanagement.admin

      gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE

      Replace the following:

      • PROJECT_ID: your project ID.
      • USER_IDENTIFIER: the identifier for your user account—for example, myemail@example.com.
      • ROLE: the IAM role that you grant to your user account.
    8. Install the Google Cloud CLI.

    9. 如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI

    10. 如要初始化 gcloud CLI,請執行下列指令:

      gcloud init
    11. Create or select a Google Cloud project.

      • Create a Google Cloud project:

        gcloud projects create PROJECT_ID

        Replace PROJECT_ID with a name for the Google Cloud project you are creating.

      • Select the Google Cloud project that you created:

        gcloud config set project PROJECT_ID

        Replace PROJECT_ID with your Google Cloud project name.

    12. Enable the Service Management API:

      gcloud services enable servicemanagement.googleapis.com
    13. Grant roles to your user account. Run the following command once for each of the following IAM roles: roles/servicemanagement.admin

      gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE

      Replace the following:

      • PROJECT_ID: your project ID.
      • USER_IDENTIFIER: the identifier for your user account—for example, myemail@example.com.
      • ROLE: the IAM role that you grant to your user account.
    14. 使用 curl 進行測試

      1. 定義便於呼叫 Google REST API 的殼層別名:

        $ alias gcurl='curl -H "Authorization: Bearer $(gcloud auth print-access-token)" -H "Content-Type: application/json"'
        
      2. 嘗試列出可公開存取的服務:

        $ gcurl https://servicemanagement.googleapis.com/v1/services
        

        如果畫面顯示服務清單,表示設定成功。

      後續步驟

      如果您要建立代管服務,且不使用 Cloud Endpoints,請按照下列步驟操作:

      1. 按照建立及刪除服務一文所述的步驟建立代管服務。這個動作會建立頂層代管服務資源。
      2. 按照「管理服務設定」所述的步驟提交服務設定,以描述服務使用的功能。

      3. 按照推行服務設定一文所述的步驟發布服務設定。