How do I Insert Google Calendar Event using Google

2019-09-16 18:36发布

问题:

I am using Google Api v3 (PHP Libraries) and wish to add an event to a user's calendar in our Google Apps domain. I have created a client ID in the Google Developer console and have granted access to it under Security in our Google Apps Admin Console. However, the event will only insert into a user's calendar if the User has previously granted access to the developer account. I do not wish every user in our domain to have to grant the developer account access to their calendar.

Is it possible under API v3 to be able to seamlessly add an event to a user's calendar?

回答1:

Granting domain-wide delegation to your service account in the Google Apps Admin Console doesn't give it access to everyone's calendar. Instead it allows the service account to impersonate any given user within your domain, and then make requests as that user.

In the PHP client library you can impersonate a user by setting the sub field on the Google_AssertionCredentials object you created.

$auth->sub = $userEmail;

We don't have a complete sample showing this for the Calendar API, but the Drive API documentation includes a sample, and the process is identical.