C
C
ceramicthree2021-07-28 01:00:09
Google
ceramicthree, 2021-07-28 01:00:09

Why is the Google API throwing a 403 error code when all permissions are requested and displayed in the access key?

I'm trying to write an application that could add Events to Google Calendar. The documentation says that for this it is necessary that access rights be granted during authorization

https://www.googleapis.com/auth/calendar , https://www.googleapis.com/auth/calendar.events

I listed these rights in the application.properties file:
spring.security.oauth2.client.registration.google.client-id=****
spring.security.oauth2.client.registration.google.client-secret=****
spring.security.oauth2.client.registration.google.scope=profile,email,https://www.googleapis.com/auth/calendar,https://www.googleapis.com/auth/calendar.events

The loadClientInfo method is responsible for obtaining a client from which you can take an access token:
private OAuth2AuthorizedClient loadClientInfo(OAuth2AuthenticationToken authentication) throws Exception {
        try {
            OAuth2AuthorizedClient client = authorizedClientService
                .loadAuthorizedClient(
                    authentication.getAuthorizedClientRegistrationId(),
                    authentication.getName());
            return client;
        } catch (Exception e) {
            throw new Exception(e.getMessage());
        }
    }

I pass this token to the method in which I create an event on the calendar.
GoogleCredential credential = new GoogleCredential().setAccessToken(tokenValue);
        Calendar service = new Calendar.Builder(httpTransport, JSON_FACTORY, credential)
            .setApplicationName(APPLICATION_NAME).build();
      // Создание события
       return service.events().insert(calendarId, event).execute();

But in response I get a 403 error
{
"error": {
"code": 403,
"message": "The request is missing a valid API key.",
"errors": [
{
"message": "The request is missing a valid API key.",
"domain": "global",
"reason": "forbidden"
}
],
"status": "PERMISSION_DENIED"
}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniil Kotyashkin, 2021-07-28
@ErVinTract

Did you translate the error? Or read? Written is not a working API Key

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question