Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
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 :
REST
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 :
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.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/02/01 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/02/01 (UTC)."],[],[],null,["# Long-running operations (Advanced)\n\nSome methods of the Cloud Translation API return a long-running operation.\nThese methods are asynchronous, and the operation may not be completed when\nthe method returns a response. You can check on the status of an operation,\nor cancel an operation.\n\nOperation status\n----------------\n\nThe following shows how to poll an operation's status. \n\n### REST\n\nCall the `get` method for the\n[`operation`](/translate/docs/reference/rest/v3/projects.locations.operations)\nresource.\n\n\nBefore using any of the request data,\nmake the following replacements:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_NUMBER_OR_ID\u003c/var\u003e: the numeric or alphanumeric ID of your Google Cloud project\n- \u003cvar translate=\"no\"\u003elocation-id\u003c/var\u003e: the location you chose for your Cloud Storage bucket\n- \u003cvar translate=\"no\"\u003eoperation-id\u003c/var\u003e: operation ID you received above\n\n\nHTTP method and URL:\n\n```\nGET https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID/locations/location-id/operations/operation-id\n```\n\nTo send your request, expand one of these options:\n\n#### curl (Linux, macOS, or Cloud Shell)\n\n| **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](/sdk/gcloud/reference/init) or [`gcloud auth login`](/sdk/gcloud/reference/auth/login) , or by using [Cloud Shell](/shell/docs), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](/sdk/gcloud/reference/auth/list).\n\n\nExecute the following command:\n\n```\ncurl -X GET \\\n -H \"Authorization: Bearer $(gcloud auth print-access-token)\" \\\n -H \"x-goog-user-project: PROJECT_NUMBER_OR_ID\" \\\n \"https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID/locations/location-id/operations/operation-id\"\n```\n\n#### PowerShell (Windows)\n\n| **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](/sdk/gcloud/reference/init) or [`gcloud auth login`](/sdk/gcloud/reference/auth/login) . You can check the currently active account by running [`gcloud auth list`](/sdk/gcloud/reference/auth/list).\n\n\nExecute the following command:\n\n```\n$cred = gcloud auth print-access-token\n$headers = @{ \"Authorization\" = \"Bearer $cred\"; \"x-goog-user-project\" = \"PROJECT_NUMBER_OR_ID\" }\n\nInvoke-WebRequest `\n -Method GET `\n -Headers $headers `\n -Uri \"https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID/locations/location-id/operations/operation-id\" | Select-Object -Expand Content\n```\n\nYou should receive a JSON response similar to the following:\n\n```\n{\n \"name\": \"projects/project-number/locations/location-id/operations/operation-id\",\n \"metadata\": {\n \"@type\": \"type.googleapis.com/google.cloud.translation.v3.SomeOperationMetadata\",\n \"state\": \"SUCCEEDED\",\n \"submitTime\": \"2019-11-27T22:59:40Z\"\n }\n}\n```\n\nWhen the operation has completed,\na `state` value of `SUCCEEDED` is returned.\n\n\u003cbr /\u003e\n\nOperation cancellation\n----------------------\n\nThe following shows how to cancel an operation. \n\n### REST\n\nCall the `cancel` method on the [`operation`](/translate/docs/reference/rest/v3/projects.locations.operations)\nresource.\n\n\nBefore using any of the request data,\nmake the following replacements:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_NUMBER_OR_ID\u003c/var\u003e: the numeric or alphanumeric ID of your Google Cloud project.\n- \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e: The location you chose when you started the operation.\n- \u003cvar translate=\"no\"\u003eOPERATION_ID\u003c/var\u003e: The ID of the operation to cancel.\n\n\nHTTP method and URL:\n\n```\nPOST https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID/locations/LOCATION_ID/operations/OPERATION_ID:cancel\n```\n\nTo send your request, expand one of these options:\n\n#### curl (Linux, macOS, or Cloud Shell)\n\n| **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](/sdk/gcloud/reference/init) or [`gcloud auth login`](/sdk/gcloud/reference/auth/login) , or by using [Cloud Shell](/shell/docs), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](/sdk/gcloud/reference/auth/list).\n\n\nExecute the following command:\n\n```\ncurl -X POST \\\n -H \"Authorization: Bearer $(gcloud auth print-access-token)\" \\\n -H \"x-goog-user-project: PROJECT_NUMBER_OR_ID\" \\\n -H \"Content-Type: application/json; charset=utf-8\" \\\n -d \"\" \\\n \"https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID/locations/LOCATION_ID/operations/OPERATION_ID:cancel\"\n```\n\n#### PowerShell (Windows)\n\n| **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](/sdk/gcloud/reference/init) or [`gcloud auth login`](/sdk/gcloud/reference/auth/login) . You can check the currently active account by running [`gcloud auth list`](/sdk/gcloud/reference/auth/list).\n\n\nExecute the following command:\n\n```\n$cred = gcloud auth print-access-token\n$headers = @{ \"Authorization\" = \"Bearer $cred\"; \"x-goog-user-project\" = \"PROJECT_NUMBER_OR_ID\" }\n\nInvoke-WebRequest `\n -Method POST `\n -Headers $headers `\n -Uri \"https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID/locations/LOCATION_ID/operations/OPERATION_ID:cancel\" | Select-Object -Expand Content\n```\n\nYou should receive a successful status code (2xx) and an empty response.\n\n\u003cbr /\u003e\n\nAdditional resources\n--------------------\n\n- For help on resolving common issues or errors, see the [Troubleshooting](/translate/troubleshooting) page."]]