Thanks for reaching out.
The first thing you need to know is that you must be a global administrator or a team administrator and team owner to add guests to the team, so you must log in as a user with the role of administrator before you can add guest users.
The guest user you are trying to add must be added in our active directory (Entra) as guest.
For adding guest user, you can't use the application permission to get the token, However you van use this permission to add member users.
You need to add TeamMember.ReadWrite.All delegates permissions
, for adding a guest user and then you need to use auth code flow to obtain an access token.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".