Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Vous pouvez obtenir un véhicule à partir d'un environnement serveur à l'aide de gRPC ou de REST. Ce document fournit des exemples pour les deux.
Utiliser gRPC pour obtenir un véhicule de livraison
Java
L'exemple suivant montre comment utiliser la bibliothèque gRPC Java pour rechercher un véhicule.
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
Pour obtenir un véhicule à partir d'un environnement serveur à l'aide de REST, effectuez un appel à GetVehicle comme suit:
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}"
Si la recherche aboutit, le corps de la réponse contient une entité de véhicule.
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/25 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Il n'y a pas l'information dont j'ai besoin","missingTheInformationINeed","thumb-down"],["Trop compliqué/Trop d'étapes","tooComplicatedTooManySteps","thumb-down"],["Obsolète","outOfDate","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Mauvais exemple/Erreur de code","samplesCodeIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/02/25 (UTC)."],[[["You can retrieve vehicle data using either gRPC or REST methods."],["This document provides code samples demonstrating how to get a vehicle using both Java gRPC and REST."],["Before making vehicle requests, review the requirements in the vehicle requests section of the introduction."],["If the vehicle lookup is successful, the response will contain a vehicle entity."]]],["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"]]