Thanks for publishing this work. It provided a good blueprint for my own efforts to import activity data from the powerbi logs into a fabric lakehouse. My problem is that I follow your recommendations regarding the service account: API permissions, group membership but I am still getting unauthorized errors when I call the API with the token. As I look into MS documentation: https://learn.microsoft.com/en-us/rest/api/power-bi/admin/get-activity-events I find that "When running under service prinicipal authentication, an app must not have any admin-consent required premissions for Power BI set on it in the Azure portal."
I've copied the content exactly, including typos. So, how can your setup work and mine fail if we are both setting the same api permissions.
Also, I got multiple syntax errors with your code regarding the scopes parameter, which is supposed to be an array of strings, not a string. Maybe these things changed after your code was published.