Obtenir des informations sur une opération de longue durée
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Obtenez l'état et les détails d'une opération de longue durée.
En savoir plus
Pour obtenir une documentation détaillée incluant cet exemple de code, consultez les articles suivants :
Exemple de code
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.
[[["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"]],[],[[["\u003cp\u003eThis code sample retrieves the status and details of a long-running operation (LRO) using the Document AI API.\u003c/p\u003e\n"],["\u003cp\u003eThe sample utilizes the \u003ccode\u003eGetOperationRequest\u003c/code\u003e to request information about a specific operation identified by its name.\u003c/p\u003e\n"],["\u003cp\u003eAuthentication to Document AI is required and can be set up using Application Default Credentials as described in the documentation.\u003c/p\u003e\n"],["\u003cp\u003eThe location of the operation must be specified, and a different API endpoint is used if the location is other than "us".\u003c/p\u003e\n"],["\u003cp\u003eFurther code samples related to Google Cloud products, including Document AI, can be explored in the Google Cloud sample browser.\u003c/p\u003e\n"]]],[],null,["# Get details about a long-running operation\n\nGet the status and details about a long-running operation (LRO).\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Managing long-running operations (LROs)](/document-ai/docs/long-running-operations)\n\nCode sample\n-----------\n\n### Python\n\n\nFor more information, see the\n[Document AI Python API\nreference documentation](/python/docs/reference/documentai/latest).\n\n\nTo authenticate to Document AI, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n from google.api_core.client_options import ClientOptions\n from google.cloud import documentai # type: ignore\n from google.longrunning.operations_pb2 import GetOperationRequest # type: ignore\n\n # TODO(developer): Uncomment these variables before running the sample.\n # location = \"YOUR_PROCESSOR_LOCATION\" # Format is \"us\" or \"eu\"\n # operation_name = \"YOUR_OPERATION_NAME\" # Format is \"projects/{project_id}/locations/{location}/operations/{operation_id}\"\n\n\n def get_operation_sample(location: str, operation_name: str) -\u003e None:\n # You must set the `api_endpoint` if you use a location other than \"us\".\n opts = ClientOptions(api_endpoint=f\"{location}-documentai.googleapis.com\")\n client = documentai.https://cloud.google.com/python/docs/reference/documentai/latest/google.cloud.documentai_v1.services.document_processor_service.DocumentProcessorServiceClient.html(client_options=opts)\n\n request = GetOperationRequest(name=operation_name)\n\n # Make GetOperation request\n operation = client.https://cloud.google.com/python/docs/reference/documentai/latest/google.cloud.documentai_v1.services.document_processor_service.DocumentProcessorServiceClient.html#google_cloud_documentai_v1_services_document_processor_service_DocumentProcessorServiceClient_get_operation(request=request)\n # Print the Operation Information\n print(operation)\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=documentai)."]]