首页 > 解决方案 > 在 Excel 查询中使用 Microsoft Graph 刷新令牌

问题描述

我正在使用 MS Excel 获取团队中的所有班次(来自 MS Teams)。我在 Azure 数据库中创建了一个 API,它能够使用 Bearer 令牌成功检索此数据。但是,此 Bearer 令牌会在 60 分钟后过期。因此,我可以使用刷新令牌(通过将 offline_access 范围添加到我的请求中来接收)。

Excel 中的当前查询如下所示:

let
    Source = Json.Document(Web.Contents("https://graph.microsoft.com/v1.0/teams/{{team-id}}/schedule/shifts?$filter=sharedShift/startDateTime ge " & Excel.CurrentWorkbook(){[Name="periodestart"]}[Content]{0}[Column1] & " and sharedShift/endDateTime le " &  Excel.CurrentWorkbook(){[Name="periodeeind"]}[Content]{0}[Column1], [Headers=[Authorization="Bearer 12345...."]])),
    value = Source[value],
    #"Converted to Table" = Table.FromList(value, Splitter.SplitByNothing(), null, null, ExtraValues.Error)
in
    #"Converted to Table"

我从 Postman 生成 Bearer 令牌,然后我可以在 Excel 中使用 1 小时。当然,这不是面向未来的,因为我希望能够随时在 Excel 中刷新我的查询以获取这些班次,并且任何使用 Excel 文件的用户都可以使用,这在令牌过期时是不可能的。因此,我的问题是:如何在我的 Excel 查询中使用刷新令牌,以便在用户想要更新查询时自动提供新的 Bearer 令牌?

谢谢!

标签: microsoft-graph-apipostmanpowerquerybearer-tokenrefresh-token

解决方案


推荐阅读