在用户允许许可后如何获取所有者的电子邮件地址
SCOPES = ['https://www.googleapis.com/auth/calendar']
flow = InstalledAppFlow.from_client_secrets_file(credentials.json, SCOPES)
creds = flow.run_local_server(port=0)
service = build('calendar', 'v3', credentials=creds)
event_body = { 'summary': 'Test calendar', 'location': 'Gurgaon, Haryana', 'description': 'A chance to hear more about Google\'s developer products.', 'start': { 'dateTime': '2020-03-28T09:00:00-07:00', 'timeZone': 'Asia/Kolkata', }, 'end': { 'dateTime': '2020-03-28T17:00:00-07:00', 'timeZone': 'America/Los_Angeles', }, 'attendees': [ {'email': '[email protected]'}, ], 'reminders': { 'useDefault': False, }, "visibility": "public", }
event = service.events().insert(calendarId='primary',body=evnt_body)
也尝试在此范围内添加'https://www.googleapis.com/auth/userinfo.email',但它在凭据中返回None。我需要在出席者列表中添加所有者用户的电子邮件地址
您可以呼叫Users.getProfile,并向userId
提供特殊值me以指示已通过身份验证的用户:
gmail_service = build('gmail', 'v1', credentials=creds)
email_address = gmail_service.users().getProfile(userId='me').execute()["emailAddress"]