Hello I'm trying to make a script to add Calendar events to my main calendar in outlook using python and the O365 package. But I keep running into various issues with creating a sample event. Here is my code below any help would be greatly appreciated.
It's stating this error:
Unable to fetch auth token. Error: (invalid_scope) AADSTS1002012: The provided value for scope basic https://graph.microsoft.com/.default/Calendars.ReadWrite.Shared is not valid. Client credential flows must have a scope value with /.default suffixed to the resource identifier (application ID URI).
Client Error: 401 Client Error: Unauthorized for url: https://graph.microsoft.com/v1.0/calendar | Error Message: Access token is empty.
code is below:
from O365 import Account, MSGraphProtocol
import win32com.client as client
from O365 import Protocol
import datetime as dt
protocol_graph = MSGraphProtocol()
scopes_graph = ['basic','https://graph.microsoft.com/.default/Calendars.ReadWrite.Shared']
account = Account(credentials,auth_flow_type= 'credentials', tenant_id= My_Tenant_Id)
if account.authenticate(scopes=scopes_graph):
print('Authenticated!')
schedule = account.schedule()
calendar = schedule.get_default_calendar()
new_event = calendar.new_event()
new_event.subject = 'Recruit George!'
new_event.location = 'Courthouse'
new_event.start = dt.datetime(2022,4,20)
new_event.save()