ไคลเอ็นต์ Java Booking API
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
คุณสามารถดาวน์โหลดไคลเอ็นต์ Java Realtime Update API เพื่อช่วยในการเริ่มต้นใช้งานการอัปเดตแบบเรียลไทม์
วิชาบังคับก่อน:
สร้างบัญชีบริการแล้ว ดาวน์โหลดคีย์ส่วนตัว
เริ่มต้น:
- ดาวน์โหลดไลบรารีของไคลเอ็นต์ 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 ลงในทรัพยากร Dependency ของโปรเจ็กต์ (รวมไฟล์ jar ไว้ในไดเรกทอรี mapsbooking และ libs-sources)
- ในไฟล์ Java ทั้ง 2 ไฟล์ ให้ทําตาม TODO เพื่อติดตั้งใช้งานให้เสร็จสมบูรณ์
ดูรายละเอียดเพิ่มเติมเกี่ยวกับ REST API ได้ที่นี่
การแก้ปัญหา:
-
เมื่อพยายามสร้างผู้ขาย/บริการใหม่โดยใช้ 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 อย่างไรก็ตาม ช่องในคำขอจะไม่แสดงในเวอร์ชันที่ใช้งานจริงเนื่องจาก merchantId หรือ serviceId ไม่ถูกต้อง หากต้องการให้ช่องแสดงผลได้ โปรดเพิ่มผู้ขายหรือบริการที่ขาดหายไปผ่าน RTU หรือฟีด
- ในฟังก์ชันการอัปเดตทั้งหมด พารามิเตอร์ "updateMask" ต้องอยู่ในรูปแบบ FieldMask เพื่อระบุฟิลด์ที่จะอัปเดต API ต้องเปลี่ยนเฉพาะค่าของช่องตามที่ระบุไว้ในมาสก์ และไม่ต้องเปลี่ยนแปลงค่าอื่นๆ หากคุณส่งสตริง updateMask ที่ไม่ถูกต้อง การอัปเดตจะไม่มีผล หากไม่มีมาสก์ฟิลด์ในการอัปเดต การดำเนินการจะมีผลกับทุกช่อง (เหมือนกับมีการระบุมาสก์ฟิลด์ของทุกช่อง) ดังนั้นหากต้องการอัปเดตทุกช่อง ให้ตั้งค่า updateMask เป็นค่าว่าง
- ช่องที่มีค่าเป็น 0 จะไม่แสดงในการตอบกลับ
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 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 get started with implementing real-time updates for your booking services.\u003c/p\u003e\n"],["\u003cp\u003eYou will need a service account with a downloaded private key to use the client.\u003c/p\u003e\n"],["\u003cp\u003eThe client library allows you to manage inventory and booking notifications, and more details on the REST API are available in the documentation.\u003c/p\u003e\n"],["\u003cp\u003eTroubleshooting information is provided for common issues such as entity conflicts, invalid IDs, and update mask usage.\u003c/p\u003e\n"],["\u003cp\u003eRemember that zero-valued fields are not displayed in responses from the API.\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 Booking API 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."]]