java - Google 日历 API:com.google.api.client.googleapis.json.GoogleJsonResponseException
问题描述
We are trying to access the users calendar for Google workspace users(formally G Suite) using google calendar API via Google cloud platform (GCP)
We followed the following setup.
1) Set up domain-wide delegation for a client Ref link (https://support.google.com/a/answer/162106?hl=en)
2) We have created a service account with an email id and got the client id as per the article above article.
3) We have then assigned Calendar API to created client id with read-only permission with below scopes
a> https://www.googleapis.com/auth/calendar.readonly
b> https://www.googleapis.com/auth/calendar.events.readonly
c> https://www.googleapis.com/auth/calendar.settings.readonly
4) Now at this point we are unable to see others users calendars except own and get the above error.
5) Also, when I tried accessing the Calendar events listing using the Google Api portal (https://developers.google.com/calendar/v3/reference/events/list?apix_params=%7B%22calendarId%22%3A%22bizzhub%40embibe.com%22%7D), I was able to authorize and see the events.
I tried accessing the events I created on the calendar using the google apis. But, I keep getting the below error.
com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 未找到
{
“代码”:404,
“错误”:[{
"domain" : "global", "message" : "Not Found", "reason" : "notFound"
}],
“未找到信息”
}
在 com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:146)
在 com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
在 com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
在 com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
在 com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1049)
在 com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
在 com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
在 com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
在 GoogleCalendarUtil2.getEventsList(GoogleCalendarUtil2.java:49)
在 GoogleCalendarMain.call(GoogleCalendarMain.java:13)
在 GoogleCalendarMain.main(GoogleCalendarMain.java:7)
下面是代码
{
"type": "service_account",
"project_id": "smartworkspace2020",
"private_key_id": "d6c2122d26ab25f908cf66d06a5ead1f77d7f013",
"private_key": "-----BEGIN PRIVATE KEY-----
-----END PRIVATE KEY-----\n",
"client_email": "bizzhub-2020-219@smartworkspace2020.iam.gserviceaccount.com",
"client_id": "117169030512379080380",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/bizzhub-2020-219%40smartworkspace2020.iam.gserviceaccount.com"
}
解决方案
推荐阅读
- java - 如何在xamarin android中启用浮动通知和锁屏通知(Java或Kotlin都可以)
- android - 如何跳过“此项目正在使用版本 xxx 的 android gradle 插件,与此版本的 android studio 不兼容”对话框?
- reactjs - Graphql 请求第一次被取消,然后使用相同的查询参数给出成功的响应
- javascript - 循环的 js localStorage 包含空字符串
- flutter - 如何重绘 StatefulWidget
- javascript - ESLint & Vue - 如何禁止使用`$log`?
- java - 如果在 java 加密中输入密钥不是 16 字节,如何填充密钥?
- sql - Postgresql 使用子字符串排序
- python - 如何将python2升级到python3?
- javascript - setTimeout 和状态集函数之间的奇怪交互