MS Graph 团队 api 无法 post 向频道发送消息并获取频道消息

MS Graph teams api cann't post message to channel and get channel's messages

我用

https://graph.microsoft.com/v1.0/teams/team_id/channels/channel_id/messages

在频道中获取消息并post向频道发送消息,但是当我想要获取这些消息时出现错误

UnknownError

当我 post 向频道发送消息时,它显示 Unauthorized

我的代码

$headers = array(
  "Content-Type: application/json",
  "Authorization: Bearer {$_SESSION["access_token"]}",
);

$post_params = json_encode(array(
  "body"=>array("content"=>"Hello World")
));

Azure 权限

此api仅支持delegated permissions,您需要授予ChannelMessage.Read.All委托权限,然后授予admin consent权限。

包括“List Channel Messages”在内的多个 API 是受保护的 API。您的管理员是否授予您权限并不重要。 Microsoft 本身也必须授予您权限。

更多信息

https://docs.microsoft.com/en-us/graph/teams-protected-apis#:~:text=Microsoft%20Teams%20APIs%20in%20Microsoft,before%20you%20can%20use%20them.

许可申请表(是的,我知道下面的表格看起来很可笑,不幸的是,这是您请求许可的唯一方式,link 也在上面的页面中给出)

https://aka.ms/teamsgraph/requestaccess

如果您使用了 GRAPH 的 BETA 端点,您可以在获得正确权限 (ChannelMessages.Read.All) 的情况下访问频道消息列表。顺便说一句,这对于生产来说不是一个好主意,但可以解决问题,因此您不需要向 MS 提出请求。

为此,您必须使用登录用户请求端点。 (授权)