Java Booking API 用戶端
您可以下載我們的 Java 即時更新 API 用戶端,開始實作即時更新功能。
必備條件:
建立服務帳戶,然後下載私密金鑰。
開始使用:
- 下載 Java 用戶端程式庫,解壓縮檔案以取得「mapsbooking」套件。
-
在 IDE 中建立 Java 專案,從這個存放區下載範例程式碼 InventoryUpdate.java 和 BookingNotification.java:
git clone https://maps-booking.googlesource.com/java-maps-booking-api-example
並將這些檔案匯入 src 目錄下的 Java 專案。
- 將私密金鑰 (JSON 檔案) 複製到 src 目錄。
- 將 Java 用戶端程式庫新增至專案的依附元件 (包括 mapsbooking 和 libs-sources 目錄下的 JAR 檔案)。
- 在兩個 Java 檔案中,按照 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 發出 replace availability 呼叫時,呼叫「不會」擲回錯誤訊息。這是因為透過 RTU 變更可用時間範圍時,系統會支援非順序執行,因此不會與 merchantId 或 serviceId 相關聯。不過,由於 merchantId 或 serviceId 無效,因此要求中的時段不會在實際環境中放送。如要讓時段可供服務,請透過 RTU 或動態饋給新增缺少的商家或服務。
- 在所有更新函式中,參數「updateMask」必須採用 FieldMask 格式,才能指定要更新的欄位。API 必須只變更遮罩中指定的欄位值,並保留其他欄位不變。如果您傳遞的 updateMask 字串有誤,更新作業就不會生效。如果更新作業中沒有欄位遮罩,則作業會套用至所有欄位 (就像已指定所有欄位的欄位遮罩一樣)。因此,如果您想更新所有欄位,只要將 updateMask 設為空白即可。
- 回應中不會顯示任何值為零的欄位。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-11-26 (世界標準時間)。
[null,null,["上次更新時間:2024-11-26 (世界標準時間)。"],[[["Download the Java real-time update API client and sample code to get started with implementing real-time updates for your booking services."],["You will need a service account with a downloaded private key to use the client."],["The client library allows you to manage inventory and booking notifications, and more details on the REST API are available in the documentation."],["Troubleshooting information is provided for common issues such as entity conflicts, invalid IDs, and update mask usage."],["Remember that zero-valued fields are not displayed in responses from the API."]]],["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"]]