The article is correct and accurate. You need to perform every single step that is described there.
How does your code look like?
Usually people use incorrect ids and/or invalid scope - double check every single value you enter.
Another common mistake is not performing "Grant admin consent" step, it is also important to allow modern authentication:
https://www.limilabs.com/blog/office365-enable-imap-pop3-smtp
Have you performed Power Shell configuration of accounts in Exchange?
Double check PowerShell them:
Get-ServicePrincipal -Organization [TODO]
Get-MailboxPermission -Identity [TODO]