Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

403 Forbidden message when calling the v3 Google Calendar API using a Service Account via OAuth 2.0

This is a follow on from my thread about a 401 error when using the Google Calendar API and OAuth2, which can be found here

This contains details of the account setup that leads onto my next question, so I wont repeat myself in this thread.

OK, so when when I call the following code to update a Calendar event I get a 403 forbidden error.

for (Event event : events.getItems())
{
    event.setSummary("XXX" + event.getSummary());

    Event updatedEvent = calendar.events().update(CALENDAR_ID, event.getId(), event).execute();
}

Here is the returned error message:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
    "code" : 403,
    "errors" : [ {
        "message" : "Forbidden"
     } ],
    "message" : "Forbidden"
}

What have I tried? Well, I have re-read the (rather poor) Google documentation about Service Accounts, re-checked my API Console account settings, tried changing the code that builds the credential (this leads to other errors so is a regression on my previous thread).

In short, nothing works, so is there anything obvious I am missing?

like image 362
Justin Phillips Avatar asked Dec 22 '12 13:12

Justin Phillips


People also ask

How do I fix Google authorization error 403?

"code": 403, "message": "The user does not have sufficient permissions for file {fileId}." To fix this error, instruct the user to contact the file's owner and request edit access. You can also check user access levels in the metadata retrieved by files.

Why do I keep seeing 403 forbidden?

The 403 Forbidden error appears when your server denies you permission to access a page on your site. This is mainly caused by a faulty security plugin, a corrupt . htaccess file, or incorrect file permissions on your server.

What is a 403 error API?

An HTTP 403 response code means that a client is forbidden from accessing a valid URL. The server understands the request, but it can't fulfill the request because of client-side issues. API Gateway APIs can return 403 responses for any of the following reasons: Issue. Response header.


1 Answers

In my case I had to enable the CalDAV API in the Google API console. It gives a 403 response if disabled.

I know this is an old question, but this might be helpful for someone.

like image 151
Stef Avatar answered Jan 01 '23 21:01

Stef