我目前正在开发一个使用 Google Calendar API 的应用程序。
请求观看内容时我完全陷入困境,因为 Google 说我为频道内容指定的 URI 不是 HTTPS :
2025-01-10 10:49:32 app-1 | 2025-01-10 09:49:32,068 CONFIG [com.goo.api.cli.htt.HttpTransport] (executor-thread-1) -------------- REQUEST --------------
2025-01-10 10:49:32 app-1 | POST https://www.googleapis.com/calendar/v3/calendars/primary/events/watch
2025-01-10 10:49:32 app-1 | Accept-Encoding: gzip
2025-01-10 10:49:32 app-1 | Authorization: <Not Logged>
2025-01-10 10:49:32 app-1 | User-Agent: OptimeApp Google-API-Java-Client/2.0.0 Google-HTTP-Java-Client/1.45.0 (gzip)
2025-01-10 10:49:32 app-1 | x-goog-api-client: gl-java/21.0.5 gdcl/2.0.0 linux/5.15.167
2025-01-10 10:49:32 app-1 | Content-Type: application/json; charset=UTF-8
2025-01-10 10:49:32 app-1 | Content-Encoding: gzip
2025-01-10 10:49:32 app-1 |
2025-01-10 10:49:32 app-1 | 2025-01-10 09:49:32,068 CONFIG [com.goo.api.cli.htt.HttpTransport] (executor-thread-1) curl -v --compressed -X POST -H 'Accept-Encoding: gzip' -H 'Authorization: <Not Logged>' -H 'User-Agent: OptimeApp Google-API-Java-Client/2.0.0 Google-HTTP-Java-Client/1.45.0 (gzip)' -H 'x-goog-api-client: gl-java/21.0.5 gdcl/2.0.0 linux/5.15.167' -H 'Content-Type: application/json; charset=UTF-8' -H 'Content-Encoding: gzip' -d '@-' -- 'https://www.googleapis.com/calendar/v3/calendars/primary/events/watch' << $$$
2025-01-10 10:49:32 app-1 | 2025-01-10 09:49:32,071 DEBUG [sun.net.www.pro.htt.HttpURLConnection] (executor-thread-1) sun.net.www.MessageHeader@614f3e811 pairs: {POST /calendar/v3/calendars/primary/events/watch HTTP/1.1: null}{Accept-Encoding: gzip}{Authorization: Bearer ya29.a0ARW5m75hrpAH13pHKKNu2-0GDitnKSWXNZ3XxVeZjjxAyU-udYVlYYzhXTCStnaRc4L3cnL9S0TInlvpUu-9qOXhLdKaUhc-yonvuxI67yKA9AsqYuXdI-AGKEbfy06vshtztOxx5eUDkuIFAW_92bfMj-tZlP7SJj35aCgYKAV0SARESFQHGX2MiPWyWyY9qojLScOSuKVuk0A0171}{User-Agent: OptimeApp Google-API-Java-Client/2.0.0 Google-HTTP-Java-Client/1.45.0 (gzip)}{x-goog-api-client: gl-java/21.0.5 gdcl/2.0.0 linux/5.15.167}{Content-Type: application/json; charset=UTF-8}{Content-Encoding: gzip}{Host: www.googleapis.com}{Accept: */*}{Connection: keep-alive}{Transfer-Encoding: chunked}
2025-01-10 10:49:32 app-1 | 2025-01-10 09:49:32,079 CONFIG [com.goo.api.cli.htt.HttpTransport] (executor-thread-1) Total: 110 bytes
2025-01-10 10:49:32 app-1 | 2025-01-10 09:49:32,079 CONFIG [com.goo.api.cli.htt.HttpTransport] (executor-thread-1) {"id":"ChannelID","resourceUri":"https://lovegiver.net/optime/googlecalendar/notifications","type":"web_hook"}
2025-01-10 10:49:32 app-1 | 2025-01-10 09:49:32,226 DEBUG [sun.net.www.pro.htt.HttpURLConnection] (executor-thread-1) sun.net.www.MessageHeader@6e009cd114 pairs: {null: HTTP/1.1 400 Bad Request}{Vary: Origin}{Vary: X-Origin}{Vary: Referer}{Content-Type: application/json; charset=UTF-8}{Content-Encoding: gzip}{Date: Fri, 10 Jan 2025 09:49:32 GMT}{Server: ESF}{X-XSS-Protection: 0}{X-Frame-Options: SAMEORIGIN}{X-Content-Type-Options: nosniff}{Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000}{x-l2-request-path: l2-managed-14}{Transfer-Encoding: chunked}
2025-01-10 10:49:32 app-1 | 2025-01-10 09:49:32,229 CONFIG [com.goo.api.cli.htt.HttpTransport] (executor-thread-1) -------------- RESPONSE --------------
2025-01-10 10:49:32 app-1 | HTTP/1.1 400 Bad Request
2025-01-10 10:49:32 app-1 | X-Frame-Options: SAMEORIGIN
2025-01-10 10:49:32 app-1 | Transfer-Encoding: chunked
2025-01-10 10:49:32 app-1 | Server: ESF
2025-01-10 10:49:32 app-1 | Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
2025-01-10 10:49:32 app-1 | X-Content-Type-Options: nosniff
2025-01-10 10:49:32 app-1 | Content-Encoding: gzip
2025-01-10 10:49:32 app-1 | Vary: Origin
2025-01-10 10:49:32 app-1 | Vary: X-Origin
2025-01-10 10:49:32 app-1 | Vary: Referer
2025-01-10 10:49:32 app-1 | X-XSS-Protection: 0
2025-01-10 10:49:32 app-1 | Date: Fri, 10 Jan 2025 09:49:32 GMT
2025-01-10 10:49:32 app-1 | Content-Type: application/json; charset=UTF-8
2025-01-10 10:49:32 app-1 | x-l2-request-path: l2-managed-14
2025-01-10 10:49:32 app-1 |
2025-01-10 10:49:32 app-1 | 2025-01-10 09:49:32,243 CONFIG [com.goo.api.cli.htt.HttpTransport] (executor-thread-1) Total: 253 bytes
2025-01-10 10:49:32 app-1 | 2025-01-10 09:49:32,243 CONFIG [com.goo.api.cli.htt.HttpTransport] (executor-thread-1) {
2025-01-10 10:49:32 app-1 | "error": {
2025-01-10 10:49:32 app-1 | "errors": [
2025-01-10 10:49:32 app-1 | {
2025-01-10 10:49:32 app-1 | "domain": "global",
2025-01-10 10:49:32 app-1 | "reason": "push.webhookUrlNotHttps",
2025-01-10 10:49:32 app-1 | "message": "WebHook callback must be HTTPS: "
2025-01-10 10:49:32 app-1 | }
2025-01-10 10:49:32 app-1 | ],
2025-01-10 10:49:32 app-1 | "code": 400,
2025-01-10 10:49:32 app-1 | "message": "WebHook callback must be HTTPS: "
2025-01-10 10:49:32 app-1 | }
2025-01-10 10:49:32 app-1 | }
2025-01-10 10:49:32 app-1 | 2025-01-10 09:49:32,248 DEBUG [org.jbo.res.rea.ser.cor.RuntimeExceptionMapper] (executor-thread-1) IOError processing HTTP request to https://lovegiver.net/optime/actions failed, the client likely terminated the connection.: com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
2025-01-10 10:49:32 app-1 | POST https://www.googleapis.com/calendar/v3/calendars/primary/events/watch
2025-01-10 10:49:32 app-1 | {
2025-01-10 10:49:32 app-1 | "code": 400,
2025-01-10 10:49:32 app-1 | "errors": [
2025-01-10 10:49:32 app-1 | {
2025-01-10 10:49:32 app-1 | "domain": "global",
2025-01-10 10:49:32 app-1 | "message": "WebHook callback must be HTTPS: ",
2025-01-10 10:49:32 app-1 | "reason": "push.webhookUrlNotHttps"
2025-01-10 10:49:32 app-1 | }
2025-01-10 10:49:32 app-1 | ],
2025-01-10 10:49:32 app-1 | "message": "WebHook callback must be HTTPS: "
2025-01-10 10:49:32 app-1 | }
构建 Watch 对象时,我使用的 URI 是 HTTPS :
URI uri = new URI("https://lovegiver.net/optime/googlecalendar/notifications");
Calendar.Events.Watch watched = service.events().watch(
"primary",
new Channel()
.setId("ChannelID")
.setType("web_hook")
.setResourceUri(uri.toURL().toString())
);
此 URI 已在 Google 控制台中声明,并包含在包含 ID 和密码的凭据.json 文件中。
该域确实存在,具有有效的非自签名证书:
2025-01-10 10:48:07 app-1 | 2025-01-10 09:48:07,344 DEBUG [jdk.eve.security] (vert.x-internal-blocking-1) X509Certificate: Alg:SHA256withRSA, Serial:473c7bd72d57274b830aaf363f5417fd79c, Subject:CN=lovegiver.net, Issuer:CN=R10, O=Let's Encrypt, C=US, Key type:RSA, Length:2048, Cert Id:1053261847, Valid from:1/10/25, 8:48 AM, Valid until:4/10/25, 8:48 AM
控制器中也存在端点:
@Path("/notifications")
@POST
public Response watch(Object payload) {
LOG.debug("WATCH function");
return Response.ok().build();
}
此时,我无法理解我错过了什么,我希望有人能够指出我所犯的错误。
感谢您的宝贵时间。
问题出在我用来声明响应 URI 的属性中:
Calendar.Events.Watch watched = calendar.events().watch(
"primary",
new Channel()
.setId(uuid)
.setType("web_hook")
.setAddress(uri.toURL().toString())
);
注意变化:
setAddress(uri)
而不是setResourceUri(uri)