How to correctly obtain user's Calendar events using service account?

时间秒杀一切 提交于 2019-12-04 05:15:27

To solved this problem I had to add this service account to authorized API clients on Domain Administration. Client name is Service Account Client ID and scope was for Readonly Calendar

This consists of two different parts

  1. Creating a service account
  2. Giving it permissions to access the scopes you need

Create the service account:

  1. Go to the cloud page to administer your Service Accounts: Menu on the left side -> IAM & admin -> Service accounts. Or click on this link: https://console.cloud.google.com/iam-admin/serviceaccounts
  2. Make sure you are logged in as the user you want to use, and check that the organization is correctly selected
  3. Create a new service account with Project Viewer role (you can change this later), and download the .json file with the credentials when you click to create a key.
  4. Edit the service account and enable G Suite Domain-wide Delegation
  5. Take note of the Client ID. (NOT the Key ID)

Give it permissions:

  1. Go to admin.google.com
  2. Make sure you are logged in as the user with admin rights.
  3. Then go to Security -> Settings -> Advanced settings -> Manage API client access
  4. In client name fill in the Client ID you copied above (NOT the Key id)
  5. Fill in the scopes you need and authorize the service account. ie:

    https://www.googleapis.com/auth/calendar.readonly,https://www.googleapis.com/auth/gmail.readonly
    

I tested the Python samples I link in the sources, and can confirm this works as expected.

Sources: https://developers.google.com/identity/protocols/OAuth2ServiceAccount https://support.google.com/a/answer/162106?hl=en

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!