首页 > 解决方案 > 尝试查询 Microsoft Graph 的 getActivitiesByInterval 路由时出现错误 500

问题描述

我使用 clientCredentials 成功检索了 Microsoft Graph 令牌,但是当我尝试查询 getActivitiesByInterval 路由(对于 SharePoint 网站)时,我收到了 HTTP 500:

    "code": "generalException",
    "message": "The remote server returned an error: (500) Internal Server Error."

我注册的应用程序在 Microsoft Graph 上具有以下权限(Application)(Files.Read.All、Files.ReadWrite.All、Sites.Read.All、Sites.ReadWrite.All、User.Read.All)。如果我使用从图形资源管理器中检索到的令牌执行完全相同的查询,我会收到带有我要求的内容的 HTTP 200。

我使用的令牌似乎是正确的,因为我可以在没有 HTTP 500 的情况下检索 Microsoft Graph 上的用户。

我用来执行请求的代码如下(它是一个带有 Microsoft Graph 绑定以获取令牌的 Azure 函数):

[FunctionName("SharepointSitesViews")]
    public static async Task Run([TimerTrigger("0 */5 * * * *", RunOnStartup = true)]TimerInfo myTimer, 
                                 [Token(Identity = TokenIdentityMode.ClientCredentials, IdentityProvider ="AAD", Resource = "https://graph.microsoft.com")] string graphToken,
                                 ILogger log)
    {
        HttpClient client = new HttpClient();
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", graphToken);
        var response = await client.GetAsync("https://graph.microsoft.com/beta/sites/****MySiteId*****/getActivitiesByInterval?startDateTime=2018-09-12T09:59:19.817Z&endDateTime=2018-12-11T00:00:00.000Z&interval=day");
        var me = await response.Content.ReadAsStringAsync();
    }

带有 URL“ https://graph.microsoft.com/v1.0/users ”的相同代码返回 200。

我还使用 postman 重现了相同的 500 错误:

GET /beta/sites/****MySiteId****/getActivitiesByInterval?startDateTime=2018-09-12T09:59:19.817Z& endDateTime=2018-12-11T00:00:00.000Z& interval=day HTTP/1.1
Host: graph.microsoft.com
Authorization: Bearer *****myToken****
cache-control: no-cache

标签: microsoft-graph-api

解决方案


推荐阅读