Certaines méthodes de l'API Cloud Translation renvoient une opération de longue durée. Ces méthodes sont asynchrones, et l'opération risque de ne pas être terminée lorsque la méthode renvoie une réponse. Vous pouvez vérifier l'état d'une opération ou annuler cette dernière.
État de l'opération
Pour interroger l'état d'une opération, procédez comme suit :
Appelez la méthode get
pour la ressource operation
.
Avant d'utiliser les données de requête ci-dessous, effectuez les remplacements suivants :
- PROJECT_NUMBER_OR_ID : ID numérique ou alphanumérique de votre projet Google Cloud.
- location-id par l'emplacement choisi pour votre bucket Cloud Storage
- operation-id par l'ID d'opération que vous avez reçu
Méthode HTTP et URL :
GET https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID /locations/location-id /operations/operation-id
Pour envoyer votre requête, développez l'une des options suivantes :
curl (Linux, macOS ou Cloud Shell)
Exécutez la commande suivante :
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project:PROJECT_NUMBER_OR_ID " \
"https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID /locations/location-id /operations/operation-id "
PowerShell (Windows)
Exécutez la commande suivante :
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "PROJECT_NUMBER_OR_ID " }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID /locations/location-id /operations/operation-id " | Select-Object -Expand Content
Vous devriez recevoir une réponse JSON de ce type :
{ "name": "projects/project-number /locations/location-id /operations/operation-id ", "metadata": { "@type": "type.googleapis.com/google.cloud.translation.v3.SomeOperationMetadata", "state": "SUCCEEDED", "submitTime": "2019-11-27T22:59:40Z" } }
Lorsque l'opération est terminée, la valeur SUCCEEDED
est renvoyée pour state
.
Annulation de l'opération
Pour annuler une opération, procédez comme suit :
Appelez la méthode cancel
sur la ressource operation
.
Avant d'utiliser les données de requête ci-dessous, effectuez les remplacements suivants :
- PROJECT_NUMBER_OR_ID : ID numérique ou alphanumérique de votre projet Google Cloud.
- LOCATION : emplacement que vous avez choisi lors du démarrage de l'opération.
- OPERATION_ID : ID de l'opération à annuler.
Méthode HTTP et URL :
POST https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID /locations/LOCATION_ID /operations/OPERATION_ID :cancel
Pour envoyer votre requête, développez l'une des options suivantes :
curl (Linux, macOS ou Cloud Shell)
Exécutez la commande suivante :
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project:PROJECT_NUMBER_OR_ID " \
-H "Content-Type: application/json; charset=utf-8" \
-d "" \
"https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID /locations/LOCATION_ID /operations/OPERATION_ID :cancel"
PowerShell (Windows)
Exécutez la commande suivante :
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "PROJECT_NUMBER_OR_ID " }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-Uri "https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID /locations/LOCATION_ID /operations/OPERATION_ID :cancel" | Select-Object -Expand Content
Vous devriez recevoir un code d'état indiquant le succès de l'opération (2xx), ainsi qu'une réponse vide.
Autres ressources
- Pour obtenir de l'aide sur la résolution des erreurs ou des problèmes courants, consultez la page Dépannage.