首页 > 解决方案 > 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"
}

标签: javagoogle-cloud-platformgoogle-calendar-apigoogle-workspacegoogle-api-java-client

解决方案


推荐阅读