0

I have a service account, and I downloaded the credentials that look like:

{
  "installed":{
     "client_id":"abc123",
      ...
  }
}

And I go through the procedure of running the node.js based code which attempts to create the token file with getNewAccessToken, and it gives me the prompt:

Authorize this app by visiting this url: https://accounts.google.com/o/oauth2/v2/auth?ac...

When I go to the link, it asks me to log in with my google account.

That sets the token and I can send google calendar events where the calendar id is set to primary (and it is set to be from me) but I can't set the calendar id to John.Smith@mycompany.com

It says


          {
               "domain": "calendar",
               "reason": "requiredAccessLevel",
               "message": "You need to have writer access to this calendar."
          }

I am not sure how to make it so my service account can be used to send events on behalf of our staff members. Is it because when authorizing I logged in as my account instead of the service account, and if so, how do I authorize as the service account.

Update: I am using the code provided in the google calendar api quickstart guide

RobKohr
  • 6,611
  • 7
  • 48
  • 69
  • 1
    Can you please share your authentication and service init code? – Rafa Guillermo Jan 21 '21 at 08:47
  • Hi @RafaGuillermo I am using the node.js code from the google calendar api quickstart guide (updated in question) – RobKohr Jan 21 '21 at 18:47
  • You need to use domain-wide delegation. Check out [this answer](https://stackoverflow.com/questions/61744176/creating-google-calendar-events-with-a-gcp-service-account/61778053#61778053) and [this answer](https://stackoverflow.com/questions/61915432/google-oauth-using-domain-wide-delegation-and-service-account/61932919#61932919). – Rafa Guillermo Jan 28 '21 at 08:46

0 Answers0