Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Anda bisa mendapatkan kendaraan dari lingkungan server menggunakan gRPC atau REST. Dokumen ini memberikan contoh untuk keduanya.
Menggunakan gRPC untuk mendapatkan kendaraan pengiriman
Java
Contoh berikut menunjukkan cara menggunakan library gRPC Java untuk mencari
kendaraan.
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
Untuk mendapatkan kendaraan dari lingkungan server menggunakan REST, lakukan panggilan ke
GetVehicle sebagai berikut:
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}"
Jika pencarian berhasil, isi respons akan berisi entitas kendaraan.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Informasi yang saya butuhkan tidak ada","missingTheInformationINeed","thumb-down"],["Terlalu rumit/langkahnya terlalu banyak","tooComplicatedTooManySteps","thumb-down"],["Sudah usang","outOfDate","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Masalah kode / contoh","samplesCodeIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-09-10 UTC."],[[["\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,[]]