Configurazione dell'accesso completo

In questa pagina vengono descritti i passaggi di base necessari per configurare l'ambiente locale per sperimentare l'API Timeseries Insights utilizzando il comando curl.

Questa è una guida per configurare un progetto con il ruolo Proprietario set di dati insight serie temporali (roles/timeseriesinsights.datasetsOwner), che consente di creare ed eliminare set di dati.

Prima di iniziare

  1. Install the Google Cloud CLI.
  2. To initialize the gcloud CLI, run the following command:

    gcloud init
  3. 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.

  4. Attiva l'API Timeseries Insights.

    gcloud services enable timeseriesinsights.googleapis.com
  5. Set up authentication:

    1. Create the service account:

      gcloud iam service-accounts create SERVICE_ACCOUNT_NAME

      Replace SERVICE_ACCOUNT_NAME with a name for the service account.

    2. Grant the roles/timeseriesinsights.datasetsOwner IAM role to the service account:

      gcloud projects add-iam-policy-binding PROJECT_ID --member="serviceAccount:SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com" --role=roles/timeseriesinsights.datasetsOwner

      Replace the following:

      • SERVICE_ACCOUNT_NAME: the name of the service account
      • PROJECT_ID: the project ID where you created the service account
    3. Grant the required role to the principal that will create the access tokens for the service account.

      gcloud iam service-accounts add-iam-policy-binding SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com --member="user:USER_EMAIL" --role=roles/iam.serviceAccountTokenCreator

      Replace the following:

      • SERVICE_ACCOUNT_NAME: the name of the service account
      • PROJECT_ID: the project ID where you created the service account
      • USER_EMAIL: the email address for a Google Account

Testa con curl

  1. Definisci un pratico alias shell per chiamare le API REST di Google:

    alias gcurl='curl -H "Authorization: Bearer $(gcloud auth print-access-token --impersonate-service-account=SERVICE_ACCOUNT_EMAIL)" -H "Content-Type: application/json"'
    
  2. Imposta una variabile di ambiente PROJECT_ID con l'identificatore del progetto:

    PROJECT_ID="my-project-id"
    
  3. Elenca le API e i servizi abilitati in questo progetto:

    gcurl "https://timeseriesinsights.googleapis.com/v1/projects/${PROJECT_ID}/datasets"
    

    Se non vedi alcun errore, significa che la configurazione è stata eseguita correttamente.

Passaggi successivi

Segui il tutorial per scoprire di più sull'API.