提取处理器类型 (v1)

提取特定项目和位置的可用处理器类型。

代码示例

Java

如需了解详情,请参阅 Document AI Java API 参考文档。

如需向 Document AI 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证。

import com.google.cloud.documentai.v1.DocumentProcessorServiceClient;
import com.google.cloud.documentai.v1.DocumentProcessorServiceSettings;
import com.google.cloud.documentai.v1.FetchProcessorTypesRequest;
import com.google.cloud.documentai.v1.FetchProcessorTypesResponse;
import com.google.cloud.documentai.v1.ProcessorType;
import java.io.IOException;

public class FetchProcessorTypes {

  public static void main(String[] args) throws Exception {
    String projectId = "example-project-id";
    String locationId = "us";
    fetchProcessorTypes(projectId, locationId);
  }

  public static void fetchProcessorTypes(String projectId, String locationId) throws Exception {
    // Configure the client to connect to the regional endpoint.
    String endpoint = String.format("%s-documentai.googleapis.com:443", locationId);
    DocumentProcessorServiceSettings settings =
        DocumentProcessorServiceSettings.newBuilder().setEndpoint(endpoint).build();

    try (DocumentProcessorServiceClient client = DocumentProcessorServiceClient.create(settings)) {
      String parent = String.format("projects/%s/locations/%s", projectId, locationId);
      FetchProcessorTypesRequest request =
          FetchProcessorTypesRequest.newBuilder().setParent(parent).build();

      FetchProcessorTypesResponse response = client.fetchProcessorTypes(request);

      for (ProcessorType processorType : response.getProcessorTypesList()) {
        System.out.printf("Processor Type: %s%n", processorType.getType());
        System.out.printf("Category: %s%n", processorType.getCategory());
        System.out.printf("Allow Creation: %b%n", processorType.getAllowCreation());
      }
    }
  }
}

后续步骤

如需搜索和过滤其他 Google Cloud 产品的代码示例,请参阅Google Cloud 示例浏览器。