לקוח לדוגמה ב-Java
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
כדי להתחיל להטמיע את העדכונים בזמן אמת, תוכלו להוריד את לקוח ה-API של עדכוני Java בזמן אמת.
דרישה מוקדמת:
יוצרים את חשבון השירות ומורידים את המפתח הפרטי.
איך מתחילים:
- מורידים את ספריית הלקוח של Java, פותחים את הקובץ כדי לקבל את החבילה 'mapsbooking'.
-
יוצרים פרויקט Java בסביבת הפיתוח המשולבת (IDE), ומורידים את קודי הדוגמה InventoryUpdate.java ו-BookingNotification.java מהמאגר הזה:
git clone https://maps-booking.googlesource.com/java-maps-booking-api-example
וייבאו אותם לפרויקט Java בתיקיית src.
- יוצרים עותק של המפתח הפרטי (קובץ JSON) בתיקיית src.
- מוסיפים את ספריית הלקוח של Java ליחסי התלות בפרויקט (כולל קובצי jar בתיקיות mapsbooking ו-libs-sources).
- בשני קובצי ה-Java, פועלים לפי ההוראות ב-TODO כדי להשלים את ההטמעות.
כאן תוכלו למצוא פרטים נוספים על ה-API ל-REST.
פתרון בעיות:
-
כשמנסים ליצור מוכר/שירות חדשים עם merchantId או serviceId קיימים, מופיעה הודעת השגיאה הבאה:
409 Conflict
{
“code” : 409,
“errors” :
[{
“domain” : “global”,
“message” : “Requested entity already exists”,
“reason” : “alreadyExists”,
“debugInfo” : “detail: "[ORIGINAL ERROR] generic::already_exists: ...”\n"
}],
“message” : “Requested entity already exists”,
“status” : “ALREADY_EXISTS”
}
- כשמבצעים קריאה להחלפת זמינות עם merchantId או serviceId לא חוקיים, לא תופיע הודעת שגיאה. הסיבה לכך היא ששינויים בזמני הפרסום באמצעות RTU תומכים בהרצה מחוץ לסדר, ולכן הם לא משויכים למזהה מוכר או למזהה שירות. עם זאת, המיקומים בבקשה לא יוצגו בסביבת הייצור בגלל שה-merchantId או ה-serviceId לא תקינים. כדי שהמודעות יוצגו במודעות הווידאו, עליך להוסיף את המוכר או את השירות החסרים באמצעות יחידות RTU או פידים.
- בכל פונקציות העדכון, הפרמטר updateMask חייב להיות בפורמט FieldMask כדי לציין את השדות לעדכון. ה-API חייב לשנות רק את הערכים של השדות כפי שצוין במסכה, ולהשאיר את שאר השדות ללא שינוי. אם מעבירים את המחרוזת הלא נכונה של updateMask, העדכון לא ייכנס לתוקף. אם לא מצוין מסכת שדה בעדכון, הפעולה חלה על כל השדות (כאילו צוינה מסכת שדה של כל השדות). לכן, אם רוצים לעדכן את כל השדות, פשוט צריך להגדיר את updateMask כרייק.
- שדות עם ערך אפס לא מוצגים בתגובה.
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים, ניתן לעיין במדיניות האתר Google Developers. Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-07-26 (שעון UTC).
[null,null,["עדכון אחרון: 2025-07-26 (שעון UTC)."],[[["\u003cp\u003eDownload the Java real-time update API client and sample code to easily implement real-time updates for Google Maps Booking.\u003c/p\u003e\n"],["\u003cp\u003eBefore starting, ensure you have a service account created and your private key downloaded.\u003c/p\u003e\n"],["\u003cp\u003eRefer to the provided troubleshooting section for common issues and solutions during implementation.\u003c/p\u003e\n"],["\u003cp\u003eRemember to utilize the \u003ccode\u003eupdateMask\u003c/code\u003e parameter in the update functions to specify the fields to be modified.\u003c/p\u003e\n"],["\u003cp\u003eDetailed information about the REST API and FieldMask format can be found through the provided links.\u003c/p\u003e\n"]]],["Download the Java real-time update API client and library. Create a Java project, import the sample code files, `InventoryUpdate.java` and `BookingNotification.java`, and copy your private key to the `src` directory. Add the Java Client Library to your project dependencies. Follow the TODOs in the Java files to complete implementation. Be aware of 409 errors with existing IDs. Replace availability calls won't throw errors with invalid IDs. Ensure the 'updateMask' parameter is in FieldMask format in update functions.\n"],null,["# Java Sample Client\n\nYou can download our\n[Java real time update API client](https://maps-booking.googlesource.com/java-maps-booking-api-example/) to help get started implementing\nthe real time updates.\n\nPrerequisite:\n-------------\n\nHave your service account created, download your private key.\n\nGet started:\n------------\n\n1. Download the [Java client library](https://dl.google.com/mapsbooking/apiclients/v1alpha/mapsbooking_java_public.zip) unzip the file to get the 'mapsbooking' package.\n2. Create a java project in your IDE, download the sample codes\n [InventoryUpdate.java](https://maps-booking.googlesource.com/java-maps-booking-api-example/+/master/InventoryUpdate.java) and\n [BookingNotification.java](https://maps-booking.googlesource.com/java-maps-booking-api-example/+/master/BookingNotification.java) from this repo:\n\n ```java\n git clone https://maps-booking.googlesource.com/java-maps-booking-api-example\n ```\n\n and import them into your java project under src directory.\n3. Make a copy of your private key (JSON file) to the src directory.\n4. Add the Java Client Library to the dependencies of your project (include jar files under mapsbooking and libs-sources directory).\n5. In both java files, follow the TODOs to complete your implementations\n\nMore detail about the REST API can be\n[found here](/maps-booking/reference/maps-booking-api/rest).\n\nTroubleshooting:\n----------------\n\n1. When trying to create a new merchant/service with an existing merchantId or\n serviceId, you will get the following error message:\n\n ```java\n 409 Conflict\n {\n \"code\" : 409,\n \"errors\" :\n [{\n \"domain\" : \"global\",\n \"message\" : \"Requested entity already exists\",\n \"reason\" : \"alreadyExists\",\n \"debugInfo\" : \"detail: \"[ORIGINAL ERROR] generic::already_exists: ...\"\\n\"\n }],\n \"message\" : \"Requested entity already exists\",\n \"status\" : \"ALREADY_EXISTS\"\n }\n ```\n2. When making a replace availaiblity call with an invalid merchantId or serviceId, the call will **not** throw an error message. This is because changes to availability slots via RTUs support out-of-order execution and thus is not associated with a merchantId or serviceId. However, the slots in the request will not be served in the production due to the invalid merchantId or serviceId. To make the slots servable, please add the missing merchant or service via RTUs or feeds.\n3. In all update functions, the parameter 'updateMask' must be in [FieldMask](/protocol-buffers/docs/reference/google.protobuf#fieldmask) format to specify the fields to update. The API is required to only change the values of the fields as specified in the mask and leave the others untouched. If you pass the wrong updateMask string, the update will not take effect. If a field mask is not present on update, the operation applies to all fields (as if a field mask of all fields has been specified). So if you want to update all fields, just set the updateMask empty.\n4. Any field that has a zero value is not shown in the response."]]