'Get an access token for a bot with Microsoft Teams for use with graph API
You would think this would be simple, but I'm just trying to call this API:
https://docs.microsoft.com/en-us/graph/api/channel-post-messages?view=graph-rest-1.0&tabs=http
I'm trying to call it with an access token from a bot registered on Azure.
Where/how do I get the access token?
Should I be able to call this API with client credentials?
https://login.microsoftonline.com/common/oauth2/v2.0/token
Solution 1:[1]
Based on the API reference that you are trying to call, Application permission is not supported which means this API can't be called via OAuth 2.0 client credentials flow.
As you can see only Delegated permission is supported and accounts here must be work or school accounts, so if you want to call this API in your bot code directly, you can try password flow to get an access_token with delegated permission.
If you need more assistance, pls let me know.
Solution 2:[2]
If you're just trying to post to a channel, there are some other options altogether:
Posting using webhooks
If you have a bot already, and it's registered (added) to the Team, you can look into proactive messaging
They'll both achieve the goal, but it depends on who you want the message to appear to be from (e.g. must it look like it came from the user? from the bot? doesn't matter?)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Stanley Gong |
| Solution 2 | Hilton Giesenow |

