Gsuite Business - 访问用户日历

时间:2018-02-22 14:04:52

标签: python google-calendar-api gsuite

我有一个Gsuite Business帐户和几个用户,我希望(在Python中)访问所有用户的日历(readonly),以在应用程序中显示事件。

作为超级管理员,有没有办法做到这一点,而不必要求每个用户同意应用程序将访问他们的日历?

1 个答案:

答案 0 :(得分:0)

感谢@DaImTo评论,创建一个服务帐户确实是要走的路,然后跟着https://developers.google.com/identity/protocols/OAuth2ServiceAccount#delegatingauthority完成工作

from google.oauth2 import service_account
import googleapiclient.discovery

SCOPES = ['https://www.googleapis.com/auth/calendar']
SERVICE_ACCOUNT_FILE = 'GOOGLE_SECRET.json'

credentials = service_account.Credentials.from_service_account_file(
        SERVICE_ACCOUNT_FILE, scopes=SCOPES)

delegated_credentials = credentials.with_subject('address@example.com')

google_calendar = googleapiclient.discovery.build('calendar', 'v3', credentials=delegated_credentials)

events = google_calendar.events().list(
    calendarId='address@example.com',
    maxResults=10
).execute()