9

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?

Community
  • 1
  • 1
Justin Phillips
  • 1,358
  • 2
  • 12
  • 26

4 Answers4

26

Solved, thanks to this post.

You have to share the calendar from your Google Calendar account with the Service Account email that is generated in the Google API Console, e.g. 284XXXXXXXX@developer.gserviceaccount.com.

I can now update my calendar from my web service.

Community
  • 1
  • 1
Justin Phillips
  • 1,358
  • 2
  • 12
  • 26
  • hii can u plz tell me how can i share the calendar from google console?i already share this calendar for my android calendar but not getting any solution?still got this error. – Google Oct 25 '13 at 07:25
  • 1
    I'm getting error with 403 forbidden. when i shared my calendar it display my email id as owner please how to configure??? – Sadikhasan Mar 08 '14 at 12:38
  • 2
    I have the same problem. The solution is: 1) Check all credentials you setup for Calendar.Builder(). 2) Share the calendar with your Service Account and make sure "Make changes to events" is selected in "Permission Settings". – emeraldhieu Jan 19 '15 at 08:28
5

I was also getting the same error even after sharing the calendar as in the Justin's answer. After comparing with another working sample figured out that I have set

var SCOPES = ["https://www.googleapis.com/auth/calendar.readonly"];

instead of

var SCOPES = ["https://www.googleapis.com/auth/calendar"];

Hope this helps anyone who has done a similar mistake and getting this error.

Madhu
  • 1,209
  • 2
  • 22
  • 28
2

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.

Stef
  • 69
  • 7
  • Good idea to still post. As the API moves on, there are probably new reasons why this error can arise. I can't believe I posted this question seven years ago! – Justin Phillips Sep 13 '20 at 13:05
0

For me, after trying all of the suggested solutions above, nothing worked. I got it to work after looking what scopes they were using in the documentation.

I was fetching for events, and it seemed that the https://www.googleapis.com/auth/calendar scope wasn't enough. I had to add https://www.googleapis.com/auth/calendar.events as well to my scopes.

Hopefully it can help someone out there!

Sandmountain
  • 447
  • 1
  • 5
  • 13