Questa pagina mostra come iniziare a utilizzare le librerie client di Cloud per l'API AutoML AutoML. Per ulteriori informazioni sulle librerie client per le API Cloud, incluse quelle meno recenti dei client API di Google, consulta la spiegazione delle librerie client.
Installazione della libreria client
C#
Per ulteriori informazioni, consulta Configurazione di un ambiente di sviluppo C# .
install-package Google.Cloud.AutoML.V1 -pre
Go
Per ulteriori informazioni, consulta Configurazione di un ambiente di sviluppo Go.
go get cloud.google.com/go/automl
Java
Per ulteriori informazioni, consulta Configurazione di un ambiente di sviluppo Java.
If you are using Maven, add
the following to your pom.xml
file. For more information about
BOMs, see The Google Cloud Platform Libraries BOM.
If you are using Gradle, add the following to your dependencies:
If you are using sbt, add the following to your dependencies:
If you're using Visual Studio Code, IntelliJ, or Eclipse, you can add client libraries to your project using the following IDE plugins:
The plugins provide additional functionality, such as key management for service accounts. Refer to each plugin's documentation for details.
Node.js
Per ulteriori informazioni, vedi Configurazione di un ambiente di sviluppo Node.js.
npm install --save @google-cloud/automl
PHP
Per ulteriori informazioni, vedi Utilizzo di PHP su Google Cloud.
composer require google/cloud-automl
Python
Per ulteriori informazioni, consulta Configurazione di un ambiente di sviluppo Python.
pip install --upgrade google-cloud-automl
Ruby
Per ulteriori informazioni, consulta Configurazione di un ambiente di sviluppo Ruby.
gem install google-cloud-automl
Configurazione dell'autenticazione
Per eseguire la libreria client devi prima configurare l'autenticazione. Un modo per farlo è creare un account di servizio e impostare una variabile d'ambiente, come illustrato nei passaggi seguenti. Per altri metodi di autenticazione, consulta la pagina Autenticazione come account di servizio.
Console
Create a service account:
-
In the Google Cloud console, go to the Create service account page.
Go to Create service account - Select your project.
-
In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.
In the Service account description field, enter a description. For example,
Service account for quickstart
. - Click Create and continue.
-
Grant the Project > Owner role to the service account.
To grant the role, find the Select a role list, then select Project > Owner.
- Click Continue.
-
Click Done to finish creating the service account.
Do not close your browser window. You will use it in the next step.
Create a service account key:
- In the Google Cloud console, click the email address for the service account that you created.
- Click Keys.
- Click Add key, and then click Create new key.
- Click Create. A JSON key file is downloaded to your computer.
- Click Close.
gcloud
Set up authentication:
-
Create the service account:
gcloud iam service-accounts create SERVICE_ACCOUNT_NAME
Replace
SERVICE_ACCOUNT_NAME
with a name for the service account. -
Grant the
roles/owner
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/owner
Replace the following:
SERVICE_ACCOUNT_NAME
: the name of the service accountPROJECT_ID
: the project ID where you created the service account
-
Generate the key file:
gcloud iam service-accounts keys create FILE_NAME.json --iam-account=SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com
Replace the following:
FILE_NAME
: a name for the key fileSERVICE_ACCOUNT_NAME
: the name of the service accountPROJECT_ID
: the project ID where you created the service account
Fornisci le credenziali di autenticazione al codice dell'applicazione impostando la variabile di ambiente GOOGLE_APPLICATION_CREDENTIALS
. Questa variabile si applica solo alla sessione di shell attuale. Se vuoi che la variabile venga applicata a future sessioni shell, impostala nel file di avvio della shell, ad esempio nel file ~/.bashrc
o ~/.profile
.
Linux o macOS
export GOOGLE_APPLICATION_CREDENTIALS="KEY_PATH
"
Sostituisci KEY_PATH
con il percorso del file JSON che contiene le tue credenziali.
Ad esempio:
export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/service-account-file.json"
Windows
Per PowerShell:
$env:GOOGLE_APPLICATION_CREDENTIALS="KEY_PATH
"
Sostituisci KEY_PATH
con il percorso del file JSON che contiene le tue credenziali.
Ad esempio:
$env:GOOGLE_APPLICATION_CREDENTIALS="C:\Users\username\Downloads\service-account-file.json"
Per il prompt dei comandi:
set GOOGLE_APPLICATION_CREDENTIALS=KEY_PATH
Sostituisci KEY_PATH
con il percorso del file JSON che contiene le tue credenziali.
Utilizzo della libreria client
Il seguente esempio mostra come utilizzare la libreria client.
C#
Per informazioni su come utilizzare le librerie client con AutoML Object Detection, consulta le seguenti guide:
Go
Per informazioni su come utilizzare le librerie client con AutoML Object Detection, consulta le seguenti guide:
Java
Per informazioni su come utilizzare le librerie client con AutoML Object Detection, consulta le seguenti guide:
Node.js
Per informazioni su come utilizzare le librerie client con AutoML Object Detection, consulta le seguenti guide:
PHP
Per informazioni su come utilizzare le librerie client con AutoML Object Detection, consulta le seguenti guide:
Python
Per informazioni su come utilizzare le librerie client con AutoML Object Detection, consulta le seguenti guide:
Ruby
Per informazioni su come utilizzare le librerie client con AutoML Object Detection, consulta le seguenti guide: