I want to have a Google API Script deployed as a web app. I understand how to do that.
I want this script to list and add events on a Google Calendar. I have plenty of documentation and examples to do that.
I want this script to read a calendar using a service account. I have already created the service account and shared the calendar with it.
The end goal is to have a Javascript client access this script, use it to retrieve a list of events on the calendar and use it to create events on it.
What I don't understand is how to authenticate a service account. I keep seeing code like:
oauthConfig.setConsumerKey("anonymous");
oauthConfig.setConsumerSecret("anonymous");
oauthConfig.setRequestTokenUrl(
"https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope);
oauthConfig.setAuthorizationUrl("https://accounts.google.com/OAuthAuthorizeToken");
oauthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
How do I modify this to use a service account? I do not understand if/how I pass in the service account client id/email address. I also am unclear how to pass in the public/private keys.
Can anyone help?
The Drive API documentation has a really good example on how to use service account. It has steps by steps on how to create a service account, and it also includes multiple code samples. The only thing is you would have to change the scope to Calendar API from Drive API.