staticfinalStringPROJECT_ID="my-delivery-co-gcp-project";staticfinalStringVEHICLE_ID="vehicle-8241890";DeliveryServiceBlockingStubdeliveryService=DeliveryServiceGrpc.newBlockingStub(channel);// Vehicle requestStringname="providers/"+PROJECT_ID+"/deliveryVehicles/"+VEHICLE_ID;GetDeliveryVehicleRequestgetVehicleRequest=GetDeliveryVehicleRequest.newBuilder()// No need for the header.setName(name).build();try{DeliveryVehiclevehicle=deliveryService.getDeliveryVehicle(getVehicleRequest);}catch(StatusRuntimeExceptione){Statuss=e.getStatus();switch(s.getCode()){caseNOT_FOUND:break;casePERMISSION_DENIED:break;}return;}
REST
如需使用 REST 从服务器环境中获取车辆,请按如下方式调用 GetVehicle:
GEThttps://fleetengine.googleapis.com/v1/providers/<project_id>/deliveryVehicles/<vehicleId>
# Set JWT, PROJECT_ID, and VEHICLE_ID in the local environmentcurl-H"Authorization: Bearer ${JWT}"\"https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/deliveryVehicles/${VEHICLE_ID}"
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eYou can retrieve vehicle data using either gRPC or REST methods.\u003c/p\u003e\n"],["\u003cp\u003eThis document provides code samples demonstrating how to get a vehicle using both Java gRPC and REST.\u003c/p\u003e\n"],["\u003cp\u003eBefore making vehicle requests, review the requirements in the vehicle requests section of the introduction.\u003c/p\u003e\n"],["\u003cp\u003eIf the vehicle lookup is successful, the response will contain a vehicle entity.\u003c/p\u003e\n"]]],["Before requesting a vehicle, review the requirements. Vehicles can be retrieved via gRPC or REST from a server environment. Using gRPC in Java involves creating a `GetDeliveryVehicleRequest` with the project and vehicle IDs, then using `deliveryService.getDeliveryVehicle()` to fetch it. With REST, a `GET` request to the `GetVehicle` endpoint with the project and vehicle ID is required, the response is a vehicle entity.\n"],null,["# Get a vehicle\n\n| **Note:** **Before constructing a vehicle request** , read the requirements under [Vehicle requests](/maps/documentation/mobility/fleet-engine/essentials/vehicles#vehicle_requests) in the Introduction.\n\nYou can get a vehicle either from a server environment using gRPC or REST. This\ndocument provides examples for both.\n\nUse gRPC to get a delivery vehicle\n----------------------------------\n\n### Java\n\n\nThe following example shows how to use the [Java gRPC library](/maps/documentation/mobility/fleet-engine/essentials/client-libraries-trips#java) to look up a\nvehicle. \n\n static final String PROJECT_ID = \"my-delivery-co-gcp-project\";\n static final String VEHICLE_ID = \"vehicle-8241890\";\n\n DeliveryServiceBlockingStub deliveryService =\n DeliveryServiceGrpc.newBlockingStub(channel);\n\n // Vehicle request\n String name = \"providers/\" + PROJECT_ID + \"/deliveryVehicles/\" + VEHICLE_ID;\n GetDeliveryVehicleRequest getVehicleRequest = GetDeliveryVehicleRequest.newBuilder() // No need for the header\n .setName(name)\n .build();\n\n try {\n DeliveryVehicle vehicle = deliveryService.getDeliveryVehicle(getVehicleRequest);\n } catch (StatusRuntimeException e) {\n Status s = e.getStatus();\n switch (s.getCode()) {\n case NOT_FOUND:\n break;\n case PERMISSION_DENIED:\n break;\n }\n return;\n }\n\n### REST\n\n\nTo get a vehicle from a server environment using REST, make a call to\n`GetVehicle` as follows: \n\n GET https://fleetengine.googleapis.com/v1/providers/\u003cproject_id\u003e/deliveryVehicles/\u003cvehicleId\u003e\n\n # Set JWT, PROJECT_ID, and VEHICLE_ID in the local environment\n curl -H \"Authorization: Bearer ${JWT}\" \\\n \"https://fleetengine.googleapis.com/v1/providers/${PROJECT_ID}/deliveryVehicles/${VEHICLE_ID}\"\n\nIf the lookup is successful, the response body contains a vehicle entity.\n\nWhat's next\n-----------\n\n- [List delivery vehicles](/maps/documentation/mobility/fleet-engine/essentials/vehicles/on-demand-list-vehicle)"]]