Java 示例客户端
您可以下载我们的 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 调用时,该调用不会抛出错误消息。这是因为通过 RTO 更改空闲时段支持无序执行,因此不会与商家 ID 或服务 ID 相关联。不过,由于 merchantId 或 serviceId 无效,请求中的槽位不会在生产环境中投放。如需提供这些空档,请通过 RTO 或 Feed 添加缺失的商家或服务。
- 在所有更新函数中,参数“updateMask”必须采用 FieldMask 格式,才能指定要更新的字段。API 必须仅更改掩码中指定的字段的值,而对其他字段保持不变。如果您传递的 updateMask 字符串有误,更新将不会生效。如果更新时未提供字段掩码,则该操作会应用于所有字段(就像指定了所有字段的字段掩码一样)。因此,如果您想更新所有字段,只需将 updateMask 设置为空即可。
- 响应中不会显示值为零的任何字段。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-11-26。
[null,null,["最后更新时间 (UTC):2024-11-26。"],[[["Download the Java real-time update API client and sample code to easily implement real-time updates for Google Maps Booking."],["Before starting, ensure you have a service account created and your private key downloaded."],["Refer to the provided troubleshooting section for common issues and solutions during implementation."],["Remember to utilize the `updateMask` parameter in the update functions to specify the fields to be modified."],["Detailed information about the REST API and FieldMask format can be found through the provided links."]]],["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"]]