Para permitir que el código de tu aplicación use la API Video Intelligence, debes configurar las credenciales adecuadas para que tu aplicación autentique su identidad en el servicio y obtenga autorización para realizar tareas. Estos mecanismos relacionados con las credenciales se denominan esquemas de autenticación.
Google Cloud La autenticación y la autorización de APIs (que suelen agruparse como "autenticación") se suelen realizar mediante una cuenta de servicio. Una cuenta de servicio permite que tu código envíe credenciales de aplicación directamente a la API Video Intelligence. Una cuenta de servicio, al igual que una cuenta de usuario, se representa mediante una dirección de correo. A diferencia de las cuentas de usuario, las cuentas de servicio solo se asocian a una aplicación.
Habilitar la API
Para poder autenticarte, primero debes habilitar la API Video Intelligence.
- 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.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Cloud Video Intelligence API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles. -
Create a service account:
-
Ensure that you have the Create Service Accounts IAM role
(
roles/iam.serviceAccountCreator
). Learn how to grant roles. -
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.
-
Click Done to finish creating the service account.
Do not close your browser window. You will use it in the next step.
-
Ensure that you have the Create Service Accounts IAM role
(
-
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.
-
Set the environment variable
GOOGLE_APPLICATION_CREDENTIALS
to the path of the JSON file that contains your credentials. This variable applies only to your current shell session, so if you open a new session, set the variable again. -
Install the Google Cloud CLI.
-
Si utilizas un proveedor de identidades (IdP) externo, primero debes iniciar sesión en la CLI de gcloud con tu identidad federada.
-
Para inicializar gcloud CLI, ejecuta el siguiente comando:
gcloud init
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Cloud Video Intelligence API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles. -
Create a service account:
-
Ensure that you have the Create Service Accounts IAM role
(
roles/iam.serviceAccountCreator
). Learn how to grant roles. -
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.
-
Click Done to finish creating the service account.
Do not close your browser window. You will use it in the next step.
-
Ensure that you have the Create Service Accounts IAM role
(
-
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.
-
Set the environment variable
GOOGLE_APPLICATION_CREDENTIALS
to the path of the JSON file that contains your credentials. This variable applies only to your current shell session, so if you open a new session, set the variable again. -
Install the Google Cloud CLI.
-
Si utilizas un proveedor de identidades (IdP) externo, primero debes iniciar sesión en la CLI de gcloud con tu identidad federada.
-
Para inicializar gcloud CLI, ejecuta el siguiente comando:
gcloud init
En la página Credenciales de la consola Google Cloud , selecciona Crear credenciales > Clave de cuenta de servicio.
A continuación, en Cuenta de servicio, selecciona Nueva cuenta de servicio.
En el cuadro Nombre de cuenta de servicio, escribe un nombre para tu cuenta de servicio. Este nombre se usa como nombre predeterminado del ID de cuenta de servicio (a la izquierda de "@" en la dirección del ID de cuenta de servicio generado), pero puedes cambiarlo. Estos nombres son arbitrarios. Lo único importante es que los recuerdes.
En Tipo de clave, selecciona JSON para la mayoría de los proyectos nuevos.
Haz clic en Crear.
Crear una cuenta de servicio en la Google Cloud consola
Para crear una cuenta de servicio con la consola de Google Cloud , sigue estos pasos:
La consola Google Cloud genera una clave JSON (como un archivo de texto .json
), te pide que descargues el archivo en tu ordenador y
muestra el cuadro de diálogo Cuenta de servicio creada.

La clave JSON generada será similar a la siguiente clave JSON de ejemplo:
{ "type": "service_account", "project_id": "PROJECT_ID", "private_key_id": "SOME_NUMBER", "private_key": "-----BEGIN PRIVATE KEY-----\nPRIVATE_KEY\n-----END PRIVATE KEY-----\n", "client_email": "SERVICE_ACCOUNT_EMAIL", "client_id": "...", "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://accounts.google.com/o/oauth2/token", "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/SERVICE_ACCOUNT_EMAIL" }
Guarda este archivo JSON de forma segura, ya que contiene tu clave privada (y es la única copia de esa clave). Debes hacer referencia a este archivo de clave de cuenta de servicio en tu código cuando envíes solicitudes de anotación a la API Video Intelligence.
Realizar autenticaciones con credenciales de aplicación predeterminadas
La forma más sencilla de que las aplicaciones se autentiquen en la API Video Intelligence es mediante las credenciales predeterminadas de aplicación (ADC).
Los servicios que usan ADC buscan primero las credenciales en una variable de entorno GOOGLE_APPLICATION_CREDENTIALS
. A menos que necesites específicamente que ADC use otras credenciales (por ejemplo, credenciales de usuario), debes definir esta variable de entorno para que apunte al archivo de clave de tu cuenta de servicio (el archivo .json
que descargaste al crear una clave de cuenta de servicio).
$ export GOOGLE_APPLICATION_CREDENTIALS=PATH_TO_SERVICE_ACCOUNT_FILE